public interface MapTile extends Surface, MapTileRenderer, Renderable, Featurable<MapTileFeature>
A sheet id represents a tilesheet number (surface number containing tiles). A map can have one or more sheets. The map picks its resources from a sheets folder, which must contains the files images.
MapTileGame
,
Minimap
,
MapTileFeature
,
Tile
Modifier and Type | Field and Description |
---|---|
static int |
BLOC_SIZE
Number of horizontal tiles to make a bloc.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
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.
|
void |
save(FileWriting file)
Save map to specified file as binary data.
|
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.
|
renderTile
render
addFeature, getFeature, getFeatures, hasFeature
static final int BLOC_SIZE
void create(int widthInTile, int heightInTile)
setTile(Tile)
).
Previous map data (if existing) will be cleared (clear()
).widthInTile
- The map width in tile (must be strictly positive).heightInTile
- The map height in tile (must be strictly positive).LionEngineException
- If size is invalid.create(Media)
,
create(Media, Media)
void create(Media levelrip, int tileWidth, int tileHeight, int horizontalTiles)
create(int, int)
).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.LionEngineException
- If error when importing map.TilesExtractor
,
LevelRipConverter
void create(Media levelrip)
create(int, int)
).
TileSheetsConfig.FILENAME
and TileGroupsConfig.FILENAME
will be
used as default, by calling create(Media, Media)
.
If configuration files are missing, data will be extracted on the fly but not saved to file.
levelrip
- The file describing the levelrip as a single image.LionEngineException
- If error when importing map.TilesExtractor
,
LevelRipConverter
void create(Media levelrip, Media sheetsConfig)
create(int, int)
).levelrip
- The file describing the levelrip as a single image.sheetsConfig
- The file that define the sheets configuration.LionEngineException
- If error when importing map.TilesExtractor
,
LevelRipConverter
<F extends MapTileFeature> F createFeature(Class<F> feature)
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.F
- The feature type.feature
- The feature class.LionEngineException
- If unable to create feature or null
.Tile createTile(Integer sheet, int number, double x, double y)
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.LionEngineException
- If invalid arguments.void loadSheets(int tileWidth, int tileHeight, Collection<SpriteTiled> sheets)
tileWidth
- The tile width.tileHeight
- The tile height.sheets
- The sheets reference.void loadSheets(Media sheetsConfig)
sheetsConfig
- The file that define the sheets configuration.LionEngineException
- If error when reading sheets.void load(FileReading file) throws IOException
Data are loaded this way (see 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
file
- The input level file.IOException
- If error on reading.void save(FileWriting file) throws IOException
(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)
file
- The output level file.IOException
- If error on writing.void append(MapTile map, int offsetX, int offsetY)
append(MapTile, int, int)
at (getInTileWidth()
, getInTileHeight()
) will add
the new map at the top-right.map
- The map to append.offsetX
- The horizontal offset in tile (positive).offsetY
- The vertical offset in tile (positive).void clear()
loadSheets(Media)
).void setTileRenderer(MapTileRenderer renderer)
renderer
- The renderer reference.LionEngineException
- If renderer is null
.void setTile(Tile tile)
The tile location must be between 0 and map size (getInTileWidth()
, getInTileHeight()
).
If a tile exists at the tile location, it will be removed.
tile
- The tile reference.LionEngineException
- If outside map range.Tile getTile(int tx, int ty)
null
, this
means that there is not tile at this location. It is not an error, just a way to avoid useless tile storage.tx
- The horizontal tile index location.ty
- The vertical tile index location.null
if none.Tile getTile(Localizable localizable, int offsetX, int offsetY)
localizable
- The localizable reference.offsetX
- The horizontal offset search.offsetY
- The vertical offset search.null
if none.Tile getTileAt(double x, double y)
x
- The horizontal location.y
- The vertical location.null
if none.Collection<Tile> getNeighbors(Tile tile)
tile
- The tile reference.Collection<Tile> getTilesHit(double ox, double oy, double x, double y)
ox
- The old horizontal location.oy
- The old vertical location.x
- The current horizontal location.y
- The current vertical location.int getInTileX(Localizable localizable)
localizable
- The localizable reference.int getInTileY(Localizable localizable)
localizable
- The localizable reference.Media getSheetsConfig()
Collection<Integer> getSheets()
SpriteTiled getSheet(Integer sheet)
sheet
- The sheet id.LionEngineException
- If sheet not found.int getSheetsNumber()
int getTilesNumber()
null
).null
tile.int getTileWidth()
int getTileHeight()
int getInTileWidth()
int getInTileHeight()
int getInTileRadius()
boolean isCreated()
true
if created, false
else.Copyright © 2016 Byron 3D Games Studio. All rights reserved.