|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.b3dgs.lionengine.game.map.AbstractTileMap<TTile>
TTile
- tile type used.public abstract class AbstractTileMap<TTile extends DefaultTile>
Abstract representation of a standard tile based map. This class uses a List of List to store tiles, a TreeMap to store patterns references (TiledSprite), and collisions. The way to prepare a map is the following:
A simple call to load(...) will automatically perform theses operations.create(width, height); // prepare memory to store tiles loadPatterns(this.tilesDir, this.theme); // load tilesheets
DefaultTile
,
CollisionType
Field Summary | |
---|---|
protected int |
heightInTile
Map size (in tile number). |
protected int |
screenHeight
Screen height value. |
protected java.lang.String |
theme
Tiles directory and theme. |
protected int |
tileHeight
Tile size. |
protected java.lang.String |
tilesDir
Tiles directory and theme. |
protected int |
tileWidth
Tile size. |
protected int |
widthInTile
Map size (in tile number). |
Constructor Summary | |
---|---|
AbstractTileMap(java.lang.String tilesDir,
int tileWidth,
int tileHeight)
Create a new tile map. |
|
AbstractTileMap(java.lang.String tilesDir,
int tileWidth,
int tileHeight,
int screenHeight)
Create a new tile map. |
Method Summary | |
---|---|
protected void |
checkDefaultCollision(TTile tile)
This function is automatically called during load(...), in order to find tile collision if it was not saved (by checking collisions.txt data). |
void |
clear()
Remove all tiles from map. |
void |
create(int widthInTile,
int heightInTile)
Create and prepare map memory area. |
void |
createMiniMap()
Generate the minimap from the current map. |
TTile |
createTile()
Create a blank tile. |
abstract TTile |
createTile(int pattern,
int number,
int x,
int y,
java.lang.String collision)
Create a tile using specified data. |
CollisionType |
getCollision(java.lang.String name)
Get a collision from its name. |
int |
getHeightInTiles()
Get number of vertical tiles. |
java.awt.image.BufferedImage |
getMiniMap()
Get minimap surface reference. |
TiledSprite |
getPattern(java.lang.Integer pattern)
Get pattern (tilesheet) from its id. |
java.util.Set<java.lang.Integer> |
getPatterns()
Get list of patterns id. |
int |
getPatternsNumber()
Get the number of used pattern. |
java.lang.String |
getTheme()
Get map theme. |
TTile |
getTile(int v,
int h)
Get tile from specified map location (in tile index). |
int |
getTileHeight()
Get height of a tile. |
protected java.awt.Color |
getTilePixelColor(TTile tile)
Get color corresponding to the specified tile. |
int |
getTilesNumber()
Get number of active tiles (which are not null). |
int |
getTileWidth()
Get width of a tile. |
int |
getWidthInTiles()
Get number of horizontal tiles. |
void |
load(FileReader file)
Load a map from a specified file as binary data. |
void |
load(XMLNode root)
Load a map from a specified file as xml. |
void |
loadPatterns(java.lang.String dir,
java.lang.String theme)
Load map patterns (tiles surfaces) from theme name. |
protected void |
readCollisions(java.lang.String filename)
Read collisions from external file. |
void |
render(java.awt.Graphics2D g,
Camera camera,
int inTileWidth,
int inTileHeight)
Render map from camera viewpoint, showing a specified area. |
void |
render(java.awt.Graphics2D g,
int sx,
int sy,
int inTileWidth,
int inTileHeight)
Render map from starting position, showing a specified area. |
void |
render(java.awt.Graphics2D g,
int sx,
int sy,
int inTileWidth,
int inTileHeight,
int screenHeight)
Render map from starting position, showing a specified area. |
void |
render(java.awt.Graphics2D g,
int sx,
int sy,
int inTileWidth,
int inTileHeight,
int offsetX,
int offsetY)
Render map from starting position, showing a specified area, including a specific offset. |
void |
renderMiniMap(java.awt.Graphics2D g,
int x,
int y)
Render minimap on graphic output at specified location. |
void |
renderTile(java.awt.Graphics2D g,
int x,
int y,
TTile tile)
Render a tile at specified location (in real location). |
protected void |
renderTile(java.awt.Graphics2D g,
TTile tile,
int x,
int y,
int tx,
int ty)
Render a specific tile from specified location. |
void |
save(FileWriter file)
Save map to specified file as binary data. |
void |
save(XMLNode root)
Save map to specified file as xml. |
void |
setTile(int v,
int h,
TTile tile)
Set a tile at specified map indexs. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected java.lang.String tilesDir
protected java.lang.String theme
protected int tileWidth
protected int tileHeight
protected int widthInTile
protected int heightInTile
protected int screenHeight
Constructor Detail |
---|
public AbstractTileMap(java.lang.String tilesDir, int tileWidth, int tileHeight)
tilesDir
- tiles directory.tileWidth
- tile width.tileHeight
- tile height.public AbstractTileMap(java.lang.String tilesDir, int tileWidth, int tileHeight, int screenHeight)
tilesDir
- tiles directory.tileWidth
- tile width.tileHeight
- tile height.screenHeight
- screen height value.Method Detail |
---|
public void create(int widthInTile, int heightInTile)
widthInTile
- map width in tile.heightInTile
- map height in tile.public void clear()
public void loadPatterns(java.lang.String dir, java.lang.String theme)
dir
- patterns directory.theme
- theme name.protected void readCollisions(java.lang.String filename) throws java.io.IOException
filename
- file containing collisions.
java.io.FileNotFoundException
- thrown if file not found.
java.io.IOException
- thrown if an error occured while writing.public CollisionType getCollision(java.lang.String name)
name
- collision name.
public void render(java.awt.Graphics2D g, Camera camera, int inTileWidth, int inTileHeight)
g
- graphic output.camera
- camera viewpoint.inTileWidth
- number of rendered tiles in width.inTileHeight
- number of rendered tiles in height.public void render(java.awt.Graphics2D g, int sx, int sy, int inTileWidth, int inTileHeight)
g
- graphic output.sx
- starting x (view real location x).sy
- starting y (view real location y).inTileWidth
- number of rendered tiles in width.inTileHeight
- number of rendered tiles in height.public void render(java.awt.Graphics2D g, int sx, int sy, int inTileWidth, int inTileHeight, int screenHeight)
g
- graphic output.sx
- starting x (view real location x).sy
- starting y (view real location y).inTileWidth
- number of rendered tiles in width.inTileHeight
- number of rendered tiles in height.screenHeight
- manual screen height offset (to start from bottom screen to top).public void render(java.awt.Graphics2D g, int sx, int sy, int inTileWidth, int inTileHeight, int offsetX, int offsetY)
g
- graphic output.sx
- starting x (view real location x).sy
- starting y (view real location y).inTileWidth
- number of rendered tiles in width.inTileHeight
- number of rendered tiles in height.offsetX
- horizontal map offset (usually used as safe area to avoid negative tiles).offsetY
- vertical map offset (usually used as safe area to avoid negative tiles).protected void renderTile(java.awt.Graphics2D g, TTile tile, int x, int y, int tx, int ty)
g
- graphic output.tile
- tile to render.x
- location x.y
- location y.tx
- current h tile.ty
- current v tile.public void renderTile(java.awt.Graphics2D g, int x, int y, TTile tile)
TileBasedMap
renderTile
in interface TileBasedMap<TTile extends DefaultTile>
g
- graphic output.x
- real location x.y
- real location y.tile
- tile to render.public TTile createTile()
public abstract TTile createTile(int pattern, int number, int x, int y, java.lang.String collision)
pattern
- tile pattern number.number
- tile number inside pattern.x
- tile real location x.y
- tile real location y.collision
- tile collision name.
public int getPatternsNumber()
TileBasedMap
getPatternsNumber
in interface TileBasedMap<TTile extends DefaultTile>
public void save(FileWriter file) throws java.io.IOException
Collisions are not saved, because it is possible to retrieve them from collisions.txt(String) theme (short) width in tiles (short) height in tiles (byte) tile width (use of byte because tile width < 255) (byte) tile height (use of byte because tile height < 255) (short) tiles number for each tile, call tile.save(file)
file
- output file.
java.io.IOException
- thrown in case of output error.public void load(FileReader file) throws java.io.IOException
(String) theme (short) width in tiles (short) height in tiles (byte) tile width (byte) tile height (short) tiles number for n = 0 to tileNumber create blank tile call tile.load(file) call this.setTile(...) to update map with this new tile
file
- input file.
java.io.IOException
- thrown in case of output error.public void save(XMLNode root)
Collisions are not saved, because it is possible to retrieve them from collisions.txt(String) theme (integer) width in tiles (integer) height in tiles (integer) tile width (integer tile height (integer) tiles number for each tile, call tile.save(node)
root
- output node.public void load(XMLNode root)
(String) theme (short) width in tiles (short) height in tiles (byte) tile width (byte) tile height (short) tiles number for n = 0 to tileNumber create blank tile call tile.load(file) call this.setTile(...) to update map with this new tile
root
- input node.protected void checkDefaultCollision(TTile tile)
tile
- current tile to check.public void setTile(int v, int h, TTile tile)
v
- vertical index.h
- horizontal index.tile
- tile reference.public TTile getTile(int v, int h)
TileBasedMap
getTile
in interface TileBasedMap<TTile extends DefaultTile>
v
- vertical tile index location.h
- horizontal tile index location.
public TiledSprite getPattern(java.lang.Integer pattern)
pattern
- pattern id.
public java.util.Set<java.lang.Integer> getPatterns()
public java.lang.String getTheme()
public int getTilesNumber()
public int getTileWidth()
TileBasedMap
getTileWidth
in interface TileBasedMap<TTile extends DefaultTile>
public int getTileHeight()
TileBasedMap
getTileHeight
in interface TileBasedMap<TTile extends DefaultTile>
public int getWidthInTiles()
TileBasedMap
getWidthInTiles
in interface TileBasedMap<TTile extends DefaultTile>
public int getHeightInTiles()
TileBasedMap
getHeightInTiles
in interface TileBasedMap<TTile extends DefaultTile>
public void createMiniMap()
protected java.awt.Color getTilePixelColor(TTile tile)
tile
- input tile.
public void renderMiniMap(java.awt.Graphics2D g, int x, int y)
g
- graphic output.x
- location x.y
- location y.public java.awt.image.BufferedImage getMiniMap()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |