org.deken.game.map
Class TileMap

java.lang.Object
  extended by org.deken.game.map.GameMap
      extended by org.deken.game.map.TileMap
All Implemented Interfaces:
TileMapRender, Updateable

public class TileMap
extends GameMap
implements TileMapRender

Title: TileMap

Description: This tile map is for a game map that not only has width and height, but layers for the game play to occur on. The Layer is the first index in the MapElement array, this allows a layer to be sent to objects that require a MapElement array of width and height. Each entry is stored as a Sprite, so the specific object can be anything that extends the Sprite, thus allowing for animated images.

Copyright: (c) 2007

Version:
1.0
Author:
Gary Deken

Nested Class Summary
 
Nested classes/interfaces inherited from class org.deken.game.map.GameMap
GameMap.QUEUE
 
Field Summary
protected  MapElement[][][] tiles
           
 
Fields inherited from class org.deken.game.map.GameMap
background, collisionMap, components, layout, mapRenderer, mapSize, updateables
 
Constructor Summary
TileMap(int width, int height)
          Game2DMap Creates a new Game2DMap with the specified width and height (in number of tiles) of the map.
TileMap(int width, int height, int layers)
          Creates a new Game2DMap with the specified width, height and layers (in number of tiles) of the map.
TileMap(MapSize mapSize)
          Creates a new Game2DMap with the specified width, height and layers (in number of tiles) of the map.
 
Method Summary
 void addSection(Section section, GameLocation gameLocation)
          Add a Section to the specified location.
 void addSprite(Sprite sprite, GameLocation gameLocation)
          Adds the Sprite at the specified location, or does not set the tile if the specified location is outside the map.
 Sprite addSpriteCopy(Sprite sprite, GameLocation gameLocation)
          Adds the Sprite, as a copy, at the specified location, or does not set the tile if the specified location is outside the map.
 Decor addTile(Decor decor, GameLocation gameLocation)
          Adds the Decor (tile) at the specified location, or does not set the tile if the specified location is outside the map.
 Decor addTile(Decor decor, GameLocation gameLocation, boolean placeHolder, boolean nonTileCollision)
          /** Adds the Decor (tile) at the specified location, or does not set the tile if the specified location is outside the map.
 MapElement[][][] getMapElements()
          MapElement array, is stored as [Layer][X][Y].
 Actor getPlayer()
          Gets the player Sprite.
 java.util.Collection<Sprite> getSprites()
          Returns the list of all moving sprites.
 java.util.Collection<Sprite> getSprites(int z, int y)
          Gets the list of sprites for a given layer (z) and row (y)
 MapElement getTile(int x, int y, int z)
          Gets the Decor at the tile location specified.
 boolean removeSprite(Sprite sprite)
           
 Decor removeTile(GameLocation gameLocation)
           
 void setCollisionMap(CollisionMap collisionMap)
           
 void setPlayer(Actor player, GameLocation gameLocation)
          Sets the player Sprite.
 void setWrapping(MapWrapping wrapping)
           
 void update(long elapseTime)
          Update the elements in the GameMap.
 
Methods inherited from class org.deken.game.map.GameMap
addComponents, addUpdateable, clearQueueComponents, draw, getActions, getBackground, getComponentByName, getComponents, getLayout, getMapSize, getName, removeComponent, setBackground, setLayout, setMapRenderer, setMapSize, setName, setScreenSize, setupPlayer, updateQueueComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tiles

protected MapElement[][][] tiles
Constructor Detail

TileMap

public TileMap(int width,
               int height)
Game2DMap Creates a new Game2DMap with the specified width and height (in number of tiles) of the map.

Parameters:
width - int
height - int

TileMap

public TileMap(int width,
               int height,
               int layers)
Creates a new Game2DMap with the specified width, height and layers (in number of tiles) of the map.

Parameters:
width - int
height - int
layers - int

TileMap

public TileMap(MapSize mapSize)
Creates a new Game2DMap with the specified width, height and layers (in number of tiles) of the map.

Parameters:
mapSize - MapSize
Method Detail

addSection

public void addSection(Section section,
                       GameLocation gameLocation)
Description copied from class: GameMap
Add a Section to the specified location. This method should be synchronized.

Specified by:
addSection in class GameMap
Parameters:
section - Section
gameLocation - GameLocation

addSprite

public void addSprite(Sprite sprite,
                      GameLocation gameLocation)
Adds the Sprite at the specified location, or does not set the tile if the specified location is outside the map.

Specified by:
addSprite in class GameMap
Parameters:
sprite - Sprite
gameLocation - GameLocation

addSpriteCopy

public Sprite addSpriteCopy(Sprite sprite,
                            GameLocation gameLocation)
Adds the Sprite, as a copy, at the specified location, or does not set the tile if the specified location is outside the map.

Specified by:
addSpriteCopy in class GameMap
Parameters:
sprite - Sprite
gameLocation - GameLocation
Returns:
Sprite Returns the copied Sprite

addTile

public Decor addTile(Decor decor,
                     GameLocation gameLocation)
Adds the Decor (tile) at the specified location, or does not set the tile if the specified location is outside the map.

Specified by:
addTile in class GameMap
Parameters:
decor - Decor
gameLocation - GameLocation
Returns:
Decor Returns the copied Decor

addTile

public Decor addTile(Decor decor,
                     GameLocation gameLocation,
                     boolean placeHolder,
                     boolean nonTileCollision)
/** Adds the Decor (tile) at the specified location, or does not set the tile if the specified location is outside the map. If the tile is a placeHolder, it will not be rendered. If the tile is nonTileCollision, it will not be collided through normal tile collision, it will be added to the CollisionMap.

Specified by:
addTile in class GameMap
Parameters:
decor -
gameLocation -
placeHolder -
nonTileCollision -
Returns:
Decor Returns the copied Decor

removeSprite

public boolean removeSprite(Sprite sprite)
Specified by:
removeSprite in class GameMap
Returns:
sprite removed.

removeTile

public Decor removeTile(GameLocation gameLocation)
Specified by:
removeTile in class GameMap
Returns:
Decor

getTile

public MapElement getTile(int x,
                          int y,
                          int z)
Gets the Decor at the tile location specified. Returns null if there is no Sprite at that location, or if the specified location is outside the bounds of the map.

Specified by:
getTile in class GameMap
Parameters:
x - int
y - int
z - int
Returns:
Decor

update

public void update(long elapseTime)
Description copied from class: GameMap
Update the elements in the GameMap.

Specified by:
update in interface Updateable
Overrides:
update in class GameMap
Parameters:
elapseTime - long

setPlayer

public void setPlayer(Actor player,
                      GameLocation gameLocation)
Description copied from class: GameMap
Sets the player Sprite. This method should be synchronized.

Specified by:
setPlayer in class GameMap
Parameters:
player - Actor
gameLocation - GameLocation

getMapElements

public MapElement[][][] getMapElements()
MapElement array, is stored as [Layer][X][Y].

Returns:
MapElement[][][]

getPlayer

public Actor getPlayer()
Description copied from class: GameMap
Gets the player Sprite.

Specified by:
getPlayer in class GameMap
Returns:
Actor

getSprites

public java.util.Collection<Sprite> getSprites()
Description copied from class: GameMap
Returns the list of all moving sprites.

Specified by:
getSprites in class GameMap
Returns:
Collection

getSprites

public java.util.Collection<Sprite> getSprites(int z,
                                               int y)
Description copied from interface: TileMapRender
Gets the list of sprites for a given layer (z) and row (y)

Specified by:
getSprites in interface TileMapRender
Returns:
List

setCollisionMap

public void setCollisionMap(CollisionMap collisionMap)
Specified by:
setCollisionMap in class GameMap
Parameters:
collisionMap - CollisionMap

setWrapping

public void setWrapping(MapWrapping wrapping)