|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ch.aplu.jgamegrid.GGTileMap
public class GGTileMap
Class that implements a tile map, e.g. an arragement of rectangular
images of the same size like tiles on a floor. A single tile is
addressed by its horizontal and vertical indices, ranging from
0..nbHorzTiles-1 and 0..nbVertTiles-1 packed into a Location object.
Same tile images are loaded only once to save memory space. A tile image set to null is like an invisible
tile.
The tile map may be positioned relative to the playground by setting the
position of the upper left vertex in pixel units. The origin of the
coordinate system corresponds to the upper left vertex of the playground,
x-coordinate to the right, y-coordinate downwards (negative
coordinates allowed).
The tile map may be moved by setting the tile position. In every
simulation loop or when refresh() is called the images are drawn
in the following order:
- background (background image, grid, background drawing using Graphics2D)
- tile map
- actors
Be aware that the size of the tiles are given in pixel units, but
an image using a x b pixels has the size (a-1) x (b-1) in pixel units.
Method Summary | |
---|---|
java.awt.Point |
getCenter(Location loc)
Returns the current center of tile at given map location with respect to the playground coordinate system (origin at upper left vertex, x-coordinate to the left, y-coordinate downwards). |
int |
getHeigth()
Returns total height (in pixels units) of the tile map. |
int |
getNbHorzTiles()
Returns the number of horizontal tiles. |
int |
getNbVertTiles()
Returns the number of vertical tiles. |
java.awt.Point |
getPosition()
Returns current position of upper left vertex with respect to the playground coordinate system (origin at upper left vertex, x-coordinate to the left, y-coordinate downwards). |
java.awt.Point |
getUpperLeftVertex(Location loc)
Returns the current coordinates of the upper left vertex of tile at given map location with respect to the playground coordinate system (origin at upper left vertex, x-coordinate to the left, y-coordinate downwards). |
int |
getWidth()
Returns total width (in pixels units) of the tile map. |
boolean |
isTileCollisionEnabled(Location location)
Returns true, if collision notification with the given tiles is enabled. |
void |
setCollisionCircle(Location location,
java.awt.Point center,
int radius)
Selects the circle (in pixel units) relative to the tile center that is used for collision detection. |
void |
setCollisionLine(Location location,
java.awt.Point startPoint,
java.awt.Point endPoint)
Selects the line segment (in pixel units) relative to the tile that is used for collision detection. |
void |
setCollisionRectangle(Location location,
java.awt.Point center,
int width,
int height)
Selects the rectangle (in pixel units) relative to the tile that is used for collision detection. |
void |
setCollisionSpot(Location location,
java.awt.Point spot)
Selects the hot spot relative to the sprite image that is used for collision detection. |
void |
setImage(java.lang.String imagePath,
int horz,
int vert)
Sets the tile image of the tile with given indices. |
void |
setImage(java.lang.String imagePath,
Location location)
Sets the tile image of the tile with given map location.In order the image fits exactly on the tile, its size in number of pixels should be tileHeight x tileWidth given when constructing the tile map. |
void |
setPosition(java.awt.Point point)
Sets the current position of the upper left vertex with respect to the playground coordinate system (origin at upper left vertex, x-coordinate to the left, y-coordinate downwards). |
void |
setTileCollisionEnabled(Location location,
boolean enable)
Enable/disable the detection of collisions with the given tile. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public void setImage(java.lang.String imagePath, int horz, int vert)
imagePath
- the path to the image file; null if the tile is invisiblehorz
- the horizontal tile index in the range 0..nbHorzTiles-1vert
- the vertical tile index in the range 0..nbVertTiles-1public void setImage(java.lang.String imagePath, Location location)
imagePath
- the path to the image file; null if the tile is invisiblelocation
- the location of the tile within the map (0..nbHorzTiles-1, 0..nbVertTiles1)public int getNbHorzTiles()
public int getNbVertTiles()
public int getWidth()
public int getHeigth()
public java.awt.Point getPosition()
public void setPosition(java.awt.Point point)
point
- the new (ulx, uly)public java.awt.Point getUpperLeftVertex(Location loc)
loc
- the tile location within the map (0..nbHorzTiles-1, 0..nbVertTiles-1)
public java.awt.Point getCenter(Location loc)
loc
- the tile location within the map (0..nbHorzTiles-1, 0..nbVertTiles-1)
public void setTileCollisionEnabled(Location location, boolean enable)
location
- the tile location within the tile mapenable
- if true, collisions will be notifiedpublic boolean isTileCollisionEnabled(Location location)
location
- the tile location within the tile map
public void setCollisionRectangle(Location location, java.awt.Point center, int width, int height)
location
- to location of the tile within the tile mapcenter
- the rectangle center (zero at tile center)width
- the width in pixel units of the rectangle (in x-direction)height
- the height in pixel units of the rectangle (in y-direction)public void setCollisionCircle(Location location, java.awt.Point center, int radius)
location
- to location of the tile within the tile mapcenter
- circle center (zero at tile center)radius
- the radius of the circle (in pixel units)public void setCollisionLine(Location location, java.awt.Point startPoint, java.awt.Point endPoint)
location
- to location of the tile within the tile mapstartPoint
- the start point of the line (zero at image center)endPoint
- the end point of the line (zero at image center)public void setCollisionSpot(Location location, java.awt.Point spot)
location
- to location of the tile within the tile mapspot
- the hot spot (zero at image center)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |