public class MapTileGame extends Object implements MapTile
SpriteTiled
), and collisions.
The way to prepare a map is the following:
create(int, int)
// prepare memory to store tilesloadSheets(Media)
// load tile sheets
Or import a map from a level rip with create(Media, Media)
.
A simple call to load(FileReading)
will automatically perform theses operations.
Tile
Constructor and Description |
---|
MapTileGame()
Create a map tile.
|
MapTileGame(Services services)
Create a map tile.
|
Modifier and Type | Method and Description |
---|---|
void |
addFeature(MapTileFeature feature)
Add a map feature for external processing.
|
void |
append(MapTile map,
int offsetX,
int offsetY)
Append an existing map, starting at the specified offsets.
|
void |
clear()
Remove all tiles from map and clear internal data.
|
void |
create(int widthInTile,
int heightInTile)
Create and prepare map memory area.
|
void |
create(Media levelrip)
Create a map from a level rip which should be an image file (*.PNG, *.BMP) that represents the full map.
|
void |
create(Media levelrip,
int tileWidth,
int tileHeight,
int horizontalTiles)
Create a map from a level rip which should be an image file (*.PNG, *.BMP) that represents the full map.
|
void |
create(Media levelrip,
Media sheetsConfig)
Create a map from a level rip and the associated tiles configuration file.
|
<F extends MapTileFeature> |
createFeature(Class<F> feature)
Create a feature from its type, and automatically
Featurable.addFeature(F) it. |
Tile |
createTile(Integer sheet,
int number,
double x,
double y)
Create a tile.
|
<C extends MapTileFeature> |
getFeature(Class<C> feature)
Get a feature instance from its type.
|
Iterable<? extends MapTileFeature> |
getFeatures()
Get the supported features.
|
int |
getHeight() |
int |
getInTileHeight()
Get number of vertical tiles.
|
int |
getInTileRadius()
Get the radius in tile.
|
int |
getInTileWidth()
Get number of horizontal tiles.
|
int |
getInTileX(Localizable localizable)
Get location x relative to map referential as tile.
|
int |
getInTileY(Localizable localizable)
Get location y relative to map referential as tile.
|
Collection<Tile> |
getNeighbors(Tile tile)
Get the tile neighbor, directly adjacent to it.
|
SpriteTiled |
getSheet(Integer sheet)
Get sheet from its id.
|
Collection<Integer> |
getSheets()
Get list of sheets id.
|
Media |
getSheetsConfig()
Get the sheets configuration media file.
|
int |
getSheetsNumber()
Get the number of used sheets.
|
Tile |
getTile(int tx,
int ty)
Get tile from specified map location (in tile index).
|
Tile |
getTile(Localizable localizable,
int offsetX,
int offsetY)
Get the tile at the localizable.
|
Tile |
getTileAt(double x,
double y)
Get the tile at the location.
|
int |
getTileHeight()
Get height of a tile.
|
Collection<Tile> |
getTilesHit(double ox,
double oy,
double x,
double y)
Get the list of tiles from old location to current.
|
int |
getTilesNumber()
Get number of active tiles (which are not
null ). |
int |
getTileWidth()
Get width of a tile.
|
int |
getWidth() |
<C extends MapTileFeature> |
hasFeature(Class<C> feature)
Check a feature existence from its type.
|
boolean |
isCreated()
Check if map has been created.
|
void |
load(FileReading file)
Load a map from a specified file as binary data.
|
void |
loadSheets(int tileWidth,
int tileHeight,
Collection<SpriteTiled> sheets)
Load map sheets (tiles surfaces).
|
void |
loadSheets(Media sheetsConfig)
Load map sheets (tiles surfaces) from directory.
|
protected Tile |
loadTile(FileReading file,
int i)
Load tile.
|
void |
render(Graphic g) |
protected void |
render(Graphic g,
int screenHeight,
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 |
renderTile(Graphic g,
Tile tile,
int x,
int y)
Render tile on its designed location.
|
void |
save(FileWriting file)
Save map to specified file as binary data.
|
protected void |
saveTile(FileWriting file,
Tile tile)
Save tile.
|
void |
setTile(Tile tile)
Set a tile at specified map location.
|
void |
setTileRenderer(MapTileRenderer renderer)
Set an external map tile renderer, defining how tiles are rendered.
|
public MapTileGame()
render(Graphic)
). Use
MapTileGame(Services)
instead if rendering will be used.public MapTileGame(Services services)
services
- The services reference.LionEngineException
- If service not found.protected void render(Graphic g, int screenHeight, int sx, int sy, int inTileWidth, int inTileHeight, int offsetX, int offsetY)
g
- The graphic output.screenHeight
- The view height (rendering start from bottom).sx
- The starting x (view real location x).sy
- The starting y (view real location y).inTileWidth
- The number of rendered tiles in width.inTileHeight
- The number of rendered tiles in height.offsetX
- The horizontal map offset.offsetY
- The vertical map offset.protected void saveTile(FileWriting file, Tile tile) throws IOException
(integer) sheet number (integer) index number inside sheet (integer) tile location x % MapTile.BLOC_SIZE (integer tile location y
file
- The file writer reference.tile
- The tile to save.IOException
- If error on writing.protected Tile loadTile(FileReading file, int i) throws IOException
(integer) sheet number (integer) index number inside sheet (integer) tile location x (integer tile location y
file
- The file reader reference.i
- The last loaded tile number.IOException
- If error on reading.public void create(int widthInTile, int heightInTile)
MapTile
MapTile.setTile(Tile)
).
Previous map data (if existing) will be cleared (MapTile.clear()
).create
in interface MapTile
widthInTile
- The map width in tile (must be strictly positive).heightInTile
- The map height in tile (must be strictly positive).MapTile.create(Media)
,
MapTile.create(Media, Media)
public Tile createTile(Integer sheet, int number, double x, double y)
MapTile
createTile
in interface MapTile
sheet
- The sheet number (must be positive or equal to 0).number
- The tile number on sheet (must be positive or equal to 0).x
- The horizontal location.y
- The vertical location.public void load(FileReading file) throws IOException
MapTile
Data are loaded this way (see MapTile.save(FileWriting)
order):
(String)
sheets file configuration(short)
width in tiles(short)
height in tiles(byte)
tile width(byte)
tile height(short)
number of 256 horizontal blocs (widthInTile / 256) for each blocs tile(short)
number of tiles in this bloc for each tile in this bloc create blank tile call load(file) call setTile(...) to update map with this new tile
load
in interface MapTile
file
- The input level file.IOException
- If error on reading.public void save(FileWriting file) throws IOException
MapTile
(String)
sheets configuration file(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)
number of 256 horizontal blocs (widthInTile / 256) for each blocs tile(short)
number of tiles in this bloc for each tile in this bloc call tile.save(file)
save
in interface MapTile
file
- The output level file.IOException
- If error on writing.public void create(Media levelrip, int tileWidth, int tileHeight, int horizontalTiles)
MapTile
MapTile.create(int, int)
).create
in interface MapTile
levelrip
- The file describing the levelrip as a single image.tileWidth
- The tile width.tileHeight
- The tile height.horizontalTiles
- The number of horizontal tiles on sheets.TilesExtractor
,
LevelRipConverter
public void create(Media levelrip)
MapTile
MapTile.create(int, int)
).
TileSheetsConfig.FILENAME
and TileGroupsConfig.FILENAME
will be
used as default, by calling MapTile.create(Media, Media)
.
If configuration files are missing, data will be extracted on the fly but not saved to file.
create
in interface MapTile
levelrip
- The file describing the levelrip as a single image.TilesExtractor
,
LevelRipConverter
public void create(Media levelrip, Media sheetsConfig)
MapTile
MapTile.create(int, int)
).create
in interface MapTile
levelrip
- The file describing the levelrip as a single image.sheetsConfig
- The file that define the sheets configuration.TilesExtractor
,
LevelRipConverter
public <F extends MapTileFeature> F createFeature(Class<F> feature)
MapTile
Featurable.addFeature(F)
it.
The feature instance must provide a public constructor with Services
as
single argument, or the public default constructor. Else, create manually the instance and use
Featurable.addFeature(F)
on it.createFeature
in interface MapTile
F
- The feature type.feature
- The feature class.public void loadSheets(int tileWidth, int tileHeight, Collection<SpriteTiled> sheets)
MapTile
loadSheets
in interface MapTile
tileWidth
- The tile width.tileHeight
- The tile height.sheets
- The sheets reference.public void loadSheets(Media sheetsConfig)
MapTile
loadSheets
in interface MapTile
sheetsConfig
- The file that define the sheets configuration.public void append(MapTile map, int offsetX, int offsetY)
MapTile
MapTile.append(MapTile, int, int)
at (MapTile.getInTileWidth()
, MapTile.getInTileHeight()
) will add
the new map at the top-right.public void clear()
MapTile
MapTile.loadSheets(Media)
).public void addFeature(MapTileFeature feature)
Featurable
addFeature
in interface Featurable<MapTileFeature>
feature
- The feature to add.public void render(Graphic g)
render
in interface Renderable
public void renderTile(Graphic g, Tile tile, int x, int y)
MapTileRenderer
renderTile
in interface MapTileRenderer
g
- The graphic output.tile
- The tile to render.x
- The location x.y
- The location y.public void setTileRenderer(MapTileRenderer renderer)
MapTile
setTileRenderer
in interface MapTile
renderer
- The renderer reference.public void setTile(Tile tile)
MapTile
The tile location must be between 0 and map size (MapTile.getInTileWidth()
, MapTile.getInTileHeight()
).
If a tile exists at the tile location, it will be removed.
public Tile getTile(int tx, int ty)
MapTile
null
, this
means that there is not tile at this location. It is not an error, just a way to avoid useless tile storage.public Tile getTile(Localizable localizable, int offsetX, int offsetY)
MapTile
public Tile getTileAt(double x, double y)
MapTile
public Collection<Tile> getNeighbors(Tile tile)
MapTile
getNeighbors
in interface MapTile
tile
- The tile reference.public Collection<Tile> getTilesHit(double ox, double oy, double x, double y)
MapTile
getTilesHit
in interface MapTile
ox
- The old horizontal location.oy
- The old vertical location.x
- The current horizontal location.y
- The current vertical location.public int getInTileX(Localizable localizable)
MapTile
getInTileX
in interface MapTile
localizable
- The localizable reference.public int getInTileY(Localizable localizable)
MapTile
getInTileY
in interface MapTile
localizable
- The localizable reference.public Media getSheetsConfig()
MapTile
getSheetsConfig
in interface MapTile
public Collection<Integer> getSheets()
MapTile
public SpriteTiled getSheet(Integer sheet)
MapTile
public <C extends MapTileFeature> C getFeature(Class<C> feature)
Featurable
getFeature
in interface Featurable<MapTileFeature>
C
- The custom feature type.feature
- The feature type.public <C extends MapTileFeature> boolean hasFeature(Class<C> feature)
Featurable
hasFeature
in interface Featurable<MapTileFeature>
C
- The custom feature type.feature
- The feature type.true
if feature exists, false
else.public int getSheetsNumber()
MapTile
getSheetsNumber
in interface MapTile
public int getTilesNumber()
MapTile
null
).getTilesNumber
in interface MapTile
null
tile.public int getTileWidth()
MapTile
getTileWidth
in interface MapTile
public int getTileHeight()
MapTile
getTileHeight
in interface MapTile
public int getInTileWidth()
MapTile
getInTileWidth
in interface MapTile
public int getInTileHeight()
MapTile
getInTileHeight
in interface MapTile
public int getInTileRadius()
MapTile
getInTileRadius
in interface MapTile
public Iterable<? extends MapTileFeature> getFeatures()
Featurable
getFeatures
in interface Featurable<MapTileFeature>
public boolean isCreated()
MapTile
Copyright © 2016 Byron 3D Games Studio. All rights reserved.