1 package erland.game.tileadventure.isodiamond;
2
3 import erland.game.tileadventure.IrregularBlockContainerInterface;
4 import erland.game.tileadventure.BlockContainerData;
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 public class IsoDiamondBlockContainerData extends BlockContainerData {
26 private int blockDrawingOffsetX;
27 private int blockDrawingOffsetY;
28 public IsoDiamondBlockContainerData(int offsetX, int offsetY, int blockDrawingOffsetX, int blockDrawingOffsetY, int sizeX, int sizeY,int sizeZ, int squareSizeX,int squareSizeY,int squareSizeZ, int visibleSizeX, int visibleSizeY) {
29 super(offsetX,offsetY,sizeX,sizeY,sizeZ, squareSizeX,squareSizeY,squareSizeZ,visibleSizeX,visibleSizeY);
30 this.blockDrawingOffsetX = blockDrawingOffsetX;
31 this.blockDrawingOffsetY = blockDrawingOffsetY;
32 }
33
34 public int getDrawingPositionX(float x, float y, float z)
35 {
36 return getOffsetX() + blockDrawingOffsetX - getScrollingOffsetX() + getPositionX(x,y,z);
37 }
38 public int getDrawingPositionY(float x, float y, float z)
39 {
40 return getOffsetY() + blockDrawingOffsetY - getScrollingOffsetY() + getPositionY(x,y,z);
41 }
42 public int getPositionX(float x, float y, float z)
43 {
44 return ((getSquareSizeX()*getSizeX())>>1)-(getSquareSizeX()>>1)+(int)((getSquareSizeX()>>1)*x-(getSquareSizeX()>>1)*y);
45 }
46 public int getPositionY(float x, float y, float z)
47 {
48 return (int)((getSquareSizeY()>>1)*x+(getSquareSizeY()>>1)*y-getSquareSizeZ()*z);
49 }
50 public boolean getVisible(float posX, float posY,float posZ)
51 {
52 if((getPositionX(posX,posY,posZ)+getSquareSizeX())>getScrollingOffsetX() && getPositionX(posX,posY,posZ)<(getScrollingOffsetX()+getDrawingSizeX())) {
53 if((getPositionY(posX,posY,posZ)+getSquareSizeY())>getScrollingOffsetY() && getPositionY(posX,posY,posZ)<(getScrollingOffsetY()+getDrawingSizeY())) {
54 return true;
55 }
56 }
57 return false;
58 }
59
60 public int getPixelDrawingPositionX(float x, float y, float z) {
61 return getOffsetX() - getScrollingOffsetX() + getPositionX(x,y,z) + getSquareSizeX()/2;
62 }
63
64 public int getPixelDrawingPositionY(float x, float y, float z) {
65 return getOffsetY() - getScrollingOffsetY() + getPositionY(x,y,z);
66 }
67 /***
68 * Get the horizontal scrolling size
69 * @return The horizontal scrolling offset (Pixel coordinates)
70 */
71 public int getScrollingSizeX()
72 {
73 return getSizeX()*getSquareSizeX()+getSizeY()*getSquareSizeX();
74 }
75
76 /***
77 * Get the vertical scrolling size
78 * @return The vertical scrolling size (Pixel coordinates)
79 */
80 public int getScrollingSizeY()
81 {
82 return getSizeX()*getSquareSizeY()+getSizeY()*getSquareSizeY()+getSizeZ()*getSquareSizeZ();
83 }
84
85 public int getBlockPositionX(int x, int y, int z) {
86 int realX = x+getScrollingOffsetX()-getOffsetX();
87 int realY = y+getScrollingOffsetY()-getOffsetY();
88 int zeroX = getPositionX(0,0,(float)z/getSquareSizeZ())+getSquareSizeX()/2;
89 int zeroY = getPositionY(0,0,(float)z/getSquareSizeZ());
90
91 int screenDeltaX = realX-zeroX;
92 int screenDeltaY = realY-zeroY;
93
94 int worldDeltaX = (screenDeltaX+screenDeltaY*2)/getSquareSizeX();
95 int worldDeltaY = (screenDeltaY*2-screenDeltaX)/getSquareSizeX();
96
97 int posX = worldDeltaX;
98 int posY = worldDeltaY;
99
100 return posX;
101 }
102
103 public int getBlockPositionY(int x, int y, int z) {
104 int realX = x+getScrollingOffsetX()-getOffsetX();
105 int realY = y+getScrollingOffsetY()-getOffsetY();
106 int zeroX = getPositionX(0,0,(float)z/getSquareSizeZ())+getSquareSizeX()/2;
107 int zeroY = getPositionY(0,0,(float)z/getSquareSizeZ());
108
109 int screenDeltaX = realX-zeroX;
110 int screenDeltaY = realY-zeroY;
111
112 int worldDeltaX = (screenDeltaX+screenDeltaY*2)/getSquareSizeX();
113 int worldDeltaY = (screenDeltaY*2-screenDeltaX)/getSquareSizeX();
114
115 int posX = worldDeltaX;
116 int posY = worldDeltaY;
117
118 return posY;
119 }
120 }