View Javadoc

1   package erland.game.tileadventure.isodiamond;
2   
3   import erland.game.tileadventure.*;
4   import erland.game.tileadventure.rect.RectBlockContainerData;
5   import erland.game.GameEnvironmentInterface;
6   import erland.util.SubImageHandler;
7   
8   import java.awt.*;
9   
10  /*
11   * Copyright (C) 2004 Erland Isaksson (erland_i@hotmail.com)
12   *
13   * This program is free software; you can redistribute it and/or
14   * modify it under the terms of the GNU General Public License
15   * as published by the Free Software Foundation; either version 2
16   * of the License, or (at your option) any later version.
17   *
18   * This program is distributed in the hope that it will be useful,
19   * but WITHOUT ANY WARRANTY; without even the implied warranty of
20   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21   * GNU General Public License for more details.
22   *
23   * You should have received a copy of the GNU General Public License
24   * along with this program; if not, write to the Free Software
25   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26   * 
27   */
28  
29  public class IsoDiamondEnvironment implements TileGameEnvironmentInterface {
30      private GameEnvironmentInterface environment;
31      private static final int SQUARE_SIZE_X=32;
32      private static final int SQUARE_SIZE_Y=16;
33      private static final int SQUARE_SIZE_Z=8;
34  
35      public IsoDiamondEnvironment(GameEnvironmentInterface environment) {
36          this.environment = environment;
37      }
38      public BlockContainerData createBlockContainer(int offsetX, int offsetY, int sizeX, int sizeY, int sizeZ, int visibleSizeX, int visibleSizeY) {
39          return new IsoDiamondBlockContainerData(offsetX, offsetY, 0,-getSubImageHeight()+SQUARE_SIZE_Y,sizeX,sizeY, sizeZ, SQUARE_SIZE_X, SQUARE_SIZE_Y,SQUARE_SIZE_Z,visibleSizeX,visibleSizeY);
40      }
41  
42      public BlockContainerData createBlockContainer(int offsetX, int offsetY, int sizeX, int sizeY, int sizeZ) {
43          BlockContainerData data = createBlockContainer(offsetX, offsetY, sizeX,sizeY, sizeZ, sizeX*(SQUARE_SIZE_X>>1)+sizeY*(SQUARE_SIZE_X>>1),sizeY*(SQUARE_SIZE_Y>>1)+sizeX*(SQUARE_SIZE_Y>>1)+sizeZ*SQUARE_SIZE_Z);
44          data.setScrollingOffsetX(0);
45          data.setScrollingOffsetY(-sizeZ*SQUARE_SIZE_Z);
46          return data;
47      }
48      public BlockContainerData createRectBlockContainer(int offsetX, int offsetY, int sizeX, int sizeY, int sizeZ) {
49          return new RectBlockContainerData(offsetX,offsetY,0,-getSubImageHeight()+SQUARE_SIZE_Y,sizeX,sizeY,sizeZ,getSubImageWidth(),getSubImageHeight(),SQUARE_SIZE_Z,sizeX*getSubImageWidth(),sizeY*getSubImageHeight());
50      }
51      public SubImageHandler createSubImageHandler(Image image) {
52          if(image==null) {
53              image = environment.getImageCreator().createCompatibleImage(getSubImageWidth()*8,getSubImageHeight()*8,Transparency.BITMASK);
54          }
55          return new SubImageHandler(image,getSubImageWidth(),getSubImageHeight(),8,8,0,0/*-getSubImageHeight()+SQUARE_SIZE_Y*/);
56      }
57  
58      public int getSubImageWidth() {
59          return SQUARE_SIZE_X;
60      }
61  
62      public int getSubImageHeight() {
63          return SQUARE_SIZE_Z*3+SQUARE_SIZE_Y;
64      }
65  
66      public DrawMap createBlockMap() {
67          return new IsoDiamondDrawMap();
68      }
69  
70      public String getTileType() {
71          return "isodiamond";
72      }
73  }