- All Implemented Interfaces:
Activatable
,Clearable
,Anchorable
,Serializable
,Cloneable
,Iterable<YaegerEntity>
,Collection<YaegerEntity>
,List<YaegerEntity>
,RandomAccess
,SequencedCollection<YaegerEntity>
TileMap
encapsulate a two-dimensional map of instances of YaegerEntity
, which should be added to
a YaegerScene
. It is a convenience way to let Yaeger calculate the location and size of each of the entities,
and place them on the scene.
By default, a TileMap
will assume the full width of the YaegerScene
must be used for placing the
tiles. It will require a two-dimensional array that represents the scene and sets which entity should be where, and
a list of the actual entities. Of these the classes are required, since the TileMap
itself will create the
instances. It will use the two-dimensional array to calculate the location and size of each entity.
- See Also:
-
Field Summary
Fields inherited from class java.util.AbstractList
modCount
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
TileMap()
Create a newTileMap
that takes up the full width and height of theYaegerScene
.protected
TileMap
(Coordinate2D location, Size size) Create a newTileMap
with the given width and height, placed on the given x and y. -
Method Summary
Modifier and TypeMethodDescriptionvoid
activate()
Lifecycle method used to perform activation of this Game Object.void
addEntity
(int identifier, Class<? extends YaegerEntity> entityClass) <C> void
addEntity
(int identifier, Class<? extends YaegerEntity> entityClass, C configuration) abstract int[][]
The lifecycle methoddefineMap()
should be used to define the map that should be used.boolean
Return theAnchorPoint
of thisPlaceable
.YaegerEntity[][]
Return a two-dimensional array of instances ofYaegerEntity
that contains the instances created by thisTileMap
.int
hashCode()
void
setAnchorPoint
(AnchorPoint anchorPoint) Set theAnchorPoint
of thisPlaceable
.void
setTileFactory
(TileFactory tileFactory) Set theTileFactory
to be used.abstract void
The lifecycle methodsetupEntities()
should be used to add the instances ofYaegerEntity
that should be used in thisTileMap
.Methods inherited from class com.github.hanyaeger.core.entities.EntitySupplier
get, getPane, setPane
Methods inherited from class java.util.ArrayList
add, add, addAll, addAll, addFirst, addLast, clear, clone, contains, ensureCapacity, forEach, get, getFirst, getLast, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeIf, removeLast, removeRange, replaceAll, retainAll, set, size, sort, spliterator, subList, toArray, toArray, trimToSize
Methods inherited from class java.util.AbstractCollection
containsAll, toString
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface com.github.hanyaeger.core.Activatable
isActivationComplete
Methods inherited from interface java.util.Collection
parallelStream, stream, toArray
Methods inherited from interface java.util.List
containsAll, reversed
-
Constructor Details
-
TileMap
protected TileMap()Create a newTileMap
that takes up the full width and height of theYaegerScene
. -
TileMap
Create a newTileMap
with the given width and height, placed on the given x and y.- Parameters:
location
- theCoordinate2D
of the top-left corner of theTileMap
size
- theSize
of theTileMap
-
-
Method Details
-
setupEntities
public abstract void setupEntities()The lifecycle methodsetupEntities()
should be used to add the instances ofYaegerEntity
that should be used in thisTileMap
. -
defineMap
public abstract int[][] defineMap()The lifecycle methoddefineMap()
should be used to define the map that should be used. It is represented by a two-dimensional array of typeint
, where each cell represents anYaegerEntity
on the map. The first array (int[]
) defines the rows. Each entry in this array is itself an array containing the columns of the given row.This way, the following array:
int[][] map = { {0, 0, 0, 0, 0, 0, 0 }, {0, 0, 2, 0, 3, 3, 3}, {2, 3, 0, 0, 0, 0, 1}}
addEntity(int, Class)
method.- Returns:
- The two-dimensional array representing the map.
-
addEntity
Add theClass
of anSpriteEntity
that can be used in thisTileMap
. Each addedSpriteEntity
Class
must have an identifier for reference from the map. This method should only be called from the lifecycle methodsetupEntities()
.- Parameters:
identifier
- the identifier as anint
to be used from the mapentityClass
- theClass
of a subclass ofYaegerEntity
to be used for the given identifier. Note that thisYaegerEntity
should have a constructor that accepts exactly two parameters. The first one should be aCoordinate2D
and the second one aSize
. If such a constructor is not present, anYaegerEngineException
will be thrown.
-
addEntity
public <C> void addEntity(int identifier, Class<? extends YaegerEntity> entityClass, C configuration) Add theClass
of anSpriteEntity
that can be used in thisTileMap
. Each addedSpriteEntity
Class
must have an identifier for reference from the map. This method should only be called from the lifecycle methodsetupEntities()
.- Type Parameters:
C
- the type of theconfiguration
- Parameters:
identifier
- the identifier as anint
to be used from the mapentityClass
- theClass
of a subclass ofYaegerEntity
to be used for the given identifier. Note that thisYaegerEntity
should have a constructor that accepts exactly two parameters. The first one should be aCoordinate2D
and the second one aSize
. If such a constructor is not present, anYaegerEngineException
will be thrown.configuration
- an instance of typeTileMap
that is passed to the constructor of the created instance ofYaegerEntity
for configuration purposes
-
activate
public void activate()Description copied from interface:Activatable
Lifecycle method used to perform activation of this Game Object. By default, this method is empty, so it should be implemented by the Game Object, if desired.Note: This method is part of the internal API, and should not be used when implementing a Yaeger game.
- Specified by:
activate
in interfaceActivatable
-
setAnchorPoint
Description copied from interface:Anchorable
Set theAnchorPoint
of thisPlaceable
. TheAnchorPoint
can be used for aligning theYaegerEntity
, and will be used to set the given x, y-coordinate. By default, aPlaceable
will use the top-left as its anchor-point.- Specified by:
setAnchorPoint
in interfaceAnchorable
- Parameters:
anchorPoint
- theAnchorPoint
of thisYaegerEntity
-
getAnchorPoint
Description copied from interface:Anchorable
Return theAnchorPoint
of thisPlaceable
.- Specified by:
getAnchorPoint
in interfaceAnchorable
- Returns:
- the
AnchorPoint
of thisPlaceable
-
setTileFactory
Set theTileFactory
to be used.- Parameters:
tileFactory
- an instance ofTileFactory
-
getInstanceMap
Return a two-dimensional array of instances ofYaegerEntity
that contains the instances created by thisTileMap
. This way, thisTileMap
provides access to the instances it has created.The location within the two-dimensional array reflects the location in the two-dimensional array that was required in the
defineMap()
method.Whenever a
YaegerEntity
gets removed from the scene, through callingYaegerEntity.remove()
, it will also be removed from thisTileMap
, and no longer accessible through this method.- Returns:
- a two-dimensional array that contains all instances of
YaegerEntity
created by thisTileMap
-
equals
- Specified by:
equals
in interfaceCollection<YaegerEntity>
- Specified by:
equals
in interfaceList<YaegerEntity>
- Overrides:
equals
in classEntitySupplier
-
hashCode
public int hashCode()- Specified by:
hashCode
in interfaceCollection<YaegerEntity>
- Specified by:
hashCode
in interfaceList<YaegerEntity>
- Overrides:
hashCode
in classEntitySupplier
-