public abstract class AbstractTileMap<TileType extends AbstractTile> extends java.lang.Object implements TileBasedMap<TileType>
Modifier and Type | Field and Description |
---|---|
protected java.util.TreeMap<java.lang.String,CollisionType> |
collisions |
protected int |
fact |
protected int |
heightInTile |
protected int |
screenHeight |
protected java.lang.String |
theme |
protected int |
tileHeight |
protected int |
tileWidth |
protected int |
widthInTile |
DIR
Constructor and Description |
---|
AbstractTileMap(int tileWidth,
int tileHeight) |
AbstractTileMap(int tileWidth,
int tileHeight,
AbstractWorld world) |
Modifier and Type | Method and Description |
---|---|
void |
create(int widthInTile,
int heightInTile)
Create and prepare map memory area.
|
abstract TileType |
createTile(int pattern,
int number,
int x,
int y,
java.lang.String collision) |
CollisionType |
getCollision(java.lang.String name)
Get a collision from its name.
|
int |
getHeightInTiles()
Get number of vertical tiles.
|
TiledSprite |
getPattern(java.lang.Integer pattern)
Get pattern from its id.
|
java.util.Set<java.lang.Integer> |
getPatterns()
Get list of patterns id.
|
int |
getPatternsNumber()
Get the number of pattern used.
|
java.lang.String |
getTheme()
Get map theme.
|
TileType |
getTile(int v,
int h)
Get tile at specified location.
|
int |
getTileHeight()
Get height of a 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.
|
abstract void |
load(FileReader file)
Load a map from a specified file as binary data.
|
void |
loadPatterns(java.lang.String theme)
Load map patterns (tiles surfaces) from theme name.
|
abstract void |
loadXML(XMLNode root)
Load a map from a specified file as xml.
|
protected void |
readCollisions(java.lang.String filename)
Read collisions from external file.
|
void |
render(java.awt.Graphics2D g,
int sx,
int sy,
int inTileWidth,
int inTileHeight)
Render map from starting position, in defined area.
|
void |
render(java.awt.Graphics2D g,
int sx,
int sy,
int inTileWidth,
int inTileHeight,
int screenHeight)
Render map from starting position, in defined area (usualy used in resizable panels).
|
void |
render(java.awt.Graphics2D g,
int sx,
int sy,
int inTileWidth,
int inTileHeight,
int offsetX,
int offsetY)
Render map from starting position, in defined area, including a specific offset.
|
void |
renderTile(java.awt.Graphics2D g,
int x,
int y,
TileType tile)
Render a tile at specified location.
|
protected void |
renderTile(java.awt.Graphics2D g,
TileType tile,
int tx,
int ty)
Render a specific tile from specified location (different to the other renderTile, as it is called in render function).
|
abstract void |
save(FileWriter file)
Save map to specified file as binary data.
|
abstract void |
saveXML(XMLNode root)
Save map to specified file as xml.
|
void |
setTile(int v,
int h,
TileType tile)
Set a tile at specified map indexs.
|
protected java.util.TreeMap<java.lang.String,CollisionType> collisions
protected java.lang.String theme
protected int tileWidth
protected int tileHeight
protected int widthInTile
protected int heightInTile
protected int screenHeight
protected int fact
public AbstractTileMap(int tileWidth, int tileHeight)
public AbstractTileMap(int tileWidth, int tileHeight, AbstractWorld world)
public void create(int widthInTile, int heightInTile)
widthInTile
- map width in tile.heightInTile
- map height in tile.public void loadPatterns(java.lang.String theme)
theme
- theme name.protected void readCollisions(java.lang.String filename) throws java.io.FileNotFoundException, 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 abstract TileType createTile(int pattern, int number, int x, int y, java.lang.String collision)
public CollisionType getCollision(java.lang.String name)
name
- collision name.public void render(java.awt.Graphics2D g, int sx, int sy, int inTileWidth, int inTileHeight)
g
- graphic output.sx
- starting x (player real location x).sy
- starting y (player real location y).inTileWidth
- number of rendered tile in width.inTileHeight
- number of rendered tile 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 (player real location x).sy
- starting y (player real location y).inTileWidth
- number of rendered tile in width.inTileHeight
- number of rendered tile 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 (player real location x).sy
- starting y (player real location y).inTileWidth
- number of rendered tile in width.inTileHeight
- number of rendered tile 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, TileType tile, int tx, int ty)
g
- graphic output.tile
- tile to render.tx
- location x.ty
- location y.public void renderTile(java.awt.Graphics2D g, int x, int y, TileType tile)
TileBasedMap
renderTile
in interface TileBasedMap<TileType extends AbstractTile>
g
- graphic output;x
- location x.y
- location y.tile
- tile to render.public int getPatternsNumber()
TileBasedMap
getPatternsNumber
in interface TileBasedMap<TileType extends AbstractTile>
public abstract void save(FileWriter file) throws java.io.IOException
file
- output file.java.io.IOException
- thrown in case of output error.public abstract void load(FileReader file) throws java.io.IOException
file
- input file.java.io.IOException
- thrown in case of output error.public abstract void saveXML(XMLNode root)
root
- output node.public abstract void loadXML(XMLNode root)
root
- input node.public void setTile(int v, int h, TileType tile)
v
- vertical index.h
- horizontal index.tile
- tile reference.public TileType getTile(int v, int h)
TileBasedMap
getTile
in interface TileBasedMap<TileType extends AbstractTile>
v
- vertical location (y).h
- horizontal location (x).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<TileType extends AbstractTile>
public int getTileHeight()
TileBasedMap
getTileHeight
in interface TileBasedMap<TileType extends AbstractTile>
public int getWidthInTiles()
TileBasedMap
getWidthInTiles
in interface TileBasedMap<TileType extends AbstractTile>
public int getHeightInTiles()
TileBasedMap
getHeightInTiles
in interface TileBasedMap<TileType extends AbstractTile>