public class TileMap extends Entity
Tile
s
that corresponds to an image of the game world environment
and data that corresponds to placement of game world entities.
TileMaps may be used as a background image or as a collection
of solid obstacles (using the preventSpriteOverlap(Sprite)
method).Modifier and Type | Field and Description |
---|---|
int |
mapCols
number of columns of tiles in this TileMap
|
java.lang.String[][] |
mapDataGrid
a two-dimensional array storing all the text characters
used to specify this TileMap
|
int |
mapRows
number of rows of tiles in this TileMap
|
Tile[][] |
mapTileGrid
a two-dimensional array storing only the
Tile objects
specified by this TileMap. |
java.util.ArrayList<Tile> |
mapTileList
a list containing all the
Tile objects specified by this TileMap. |
int |
tileHeight
height of each tile (in pixels)
|
java.util.ArrayList<Texture> |
tileTextureList
a list containing all the available Tile textures
loaded by the
loadTilesetImage(String) method |
int |
tileWidth
width of each tile (in pixels)
|
Constructor and Description |
---|
TileMap(int mapRows,
int mapCols,
int tileWidth,
int tileHeight)
Specify basic data for this TileMap;
additional data loaded by
loadTilesetImage(String)
and loadMapData(String[], String[], int[]) methods. |
Modifier and Type | Method and Description |
---|---|
boolean |
checkSpriteOverlap(Sprite sprite)
Check if a sprite overlaps any Tile in this TileMap.
|
void |
draw(javafx.scene.canvas.GraphicsContext context)
Render this Entity to a canvas.
|
java.util.ArrayList<Vector2> |
getSymbolPositionList(java.lang.String symbol)
Return the game world coordinates (in pixels) of every occurrence
of
symbol in map data. |
Tile |
getTileAt(int mapRow,
int mapCol)
Get the tile at the corresponding map position (if one exists).
|
void |
loadMapData(java.lang.String[] mapData,
java.lang.String[] mapTileSymbolArray,
int[] tileTextureIndexArray)
Load text data that indicates placement of Tiles and game world entities.
|
void |
loadTilesetImage(java.lang.String imageFileName)
Load a tileset -
an image consisting of smaller rectangular images
that represent possible features of the game world environment.
|
void |
preventSpriteOverlap(Sprite sprite)
Prevent sprite from overlapping with any Tile in this TileMap.
|
public int mapRows
public int mapCols
public int tileWidth
public int tileHeight
public java.lang.String[][] mapDataGrid
public Tile[][] mapTileGrid
Tile
objects
specified by this TileMap. used primarily to determine whether
a tile is adjacent to other tiles, and thereby which tile edges
should be ignored when calculating collision resolution.public java.util.ArrayList<Tile> mapTileList
Tile
objects specified by this TileMap.public java.util.ArrayList<Texture> tileTextureList
loadTilesetImage(String)
methodpublic TileMap(int mapRows, int mapCols, int tileWidth, int tileHeight)
loadTilesetImage(String)
and loadMapData(String[], String[], int[])
methods.mapRows
- number of rows of tiles in this TileMapmapCols
- number of columns of tiles in this TileMaptileWidth
- width of each tile (in pixels)tileHeight
- height of each tile (in pixels)public void loadTilesetImage(java.lang.String imageFileName)
imageFileName
- file name of the image containing tile imagespublic void loadMapData(java.lang.String[] mapData, java.lang.String[] mapTileSymbolArray, int[] tileTextureIndexArray)
mapTileSymbolArray
,
and the corresponding tileset index values are listed in tileTextureIndexArray
.
Entity placement data can be retrieved later from the method
getSymbolPositionList(String)
.
mapData = {"WWWWDWWWW",
"W.......W",
"W.E...E.W",
"W.......W",
"W...P...W",
"WWWWWWWWW"};
mapTileSymbolArray = {"W", "D"};
tileTextureIndexArray = {3, 7};
This method also determines if each Tile is adjacent to other tiles,
and sets tile edge data for use in collision resolution:
edges that occur between two adjacent tiles ("interior edges") are ignored.mapData
- an array of Strings, one String per row of the map,
each character representing a Tile or other game world entitymapTileSymbolArray
- text characters indicating Tile objectstileTextureIndexArray
- index for Tile textures corresponding to characters in mapTileSymbolArray
public Tile getTileAt(int mapRow, int mapCol)
mapRow
- map row indexmapCol
- map column indexnull
otherwisepublic java.util.ArrayList<Vector2> getSymbolPositionList(java.lang.String symbol)
symbol
in map data.symbol
- text character to locate in map datasymbol
occurs in map datapublic void draw(javafx.scene.canvas.GraphicsContext context)
Entity
public boolean checkSpriteOverlap(Sprite sprite)
sprite
- the sprite to check for overlappublic void preventSpriteOverlap(Sprite sprite)
sprite
- the sprite to prevent from overlapping with tiles