View Javadoc

1   package erland.game.tileadventure.rect;
2   
3   import erland.game.tileadventure.IrregularBlockContainerInterface;
4   import erland.game.tileadventure.BlockContainerData;
5   
6   /*
7    * Copyright (C) 2004 Erland Isaksson (erland_i@hotmail.com)
8    *
9    * This program is free software; you can redistribute it and/or
10   * modify it under the terms of the GNU General Public License
11   * as published by the Free Software Foundation; either version 2
12   * of the License, or (at your option) any later version.
13   *
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   *
19   * You should have received a copy of the GNU General Public License
20   * along with this program; if not, write to the Free Software
21   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22   *
23   */
24  
25  public class RectBlockContainerData extends BlockContainerData {
26      private int blockDrawingOffsetX;
27      private int blockDrawingOffsetY;
28      public RectBlockContainerData(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      }
31  
32      public int getDrawingPositionX(float x, float y, float z)
33      {
34          return getOffsetX() + blockDrawingOffsetX - getScrollingOffsetX() + getPositionX(x,y,z);
35      }
36      public int getDrawingPositionY(float x, float y, float z)
37      {
38          return getOffsetY() + blockDrawingOffsetY - getScrollingOffsetY() + getPositionY(x,y,z);
39      }
40      public int getPositionX(float x, float y, float z)
41      {
42          return (int)(getSquareSizeX()*x);
43      }
44      public int getPositionY(float x, float y, float z)
45      {
46          return (int)(getSquareSizeY()*y);
47      }
48      public boolean getVisible(float posX, float posY,float posZ)
49      {
50          if((getPositionX(posX,posY,posZ)+getSquareSizeX())>getScrollingOffsetX() && getPositionX(posX,posY,posZ)<(getScrollingOffsetX()+getDrawingSizeX())) {
51              if((getPositionY(posX,posY,posZ)+getSquareSizeY())>getScrollingOffsetY() && getPositionY(posX,posY,posZ)<(getScrollingOffsetY()+getDrawingSizeY())) {
52                  return true;
53              }
54          }
55          return false;
56      }
57  
58      public int getPixelDrawingPositionX(float x, float y, float z) {
59          return getDrawingPositionX(x,y,z);
60      }
61  
62      public int getPixelDrawingPositionY(float x, float y, float z) {
63          return getDrawingPositionY(x,y,z);
64      }
65      /***
66  	 * Get the horizontal scrolling size
67  	 * @return The horizontal scrolling offset (Pixel coordinates)
68  	 */
69  	public int getScrollingSizeX()
70  	{
71  		return getSizeX()*getSquareSizeX();
72  	}
73  
74      /***
75  	 * Get the vertical scrolling size
76  	 * @return The vertical scrolling size (Pixel coordinates)
77  	 */
78  	public int getScrollingSizeY()
79  	{
80  		return getSizeY()*getSquareSizeY();
81  	}
82      public int getBlockPositionX(int x, int y, int z) {
83          return (x+getScrollingOffsetX()-getOffsetX())/getSquareSizeX();
84      }
85  
86      public int getBlockPositionY(int x, int y, int z) {
87          return (y+getScrollingOffsetY()-getOffsetY())/getSquareSizeY();
88      }
89  }