Module hanyaeger

Class TileMap

All Implemented Interfaces:
Activatable, Clearable, Anchorable, Serializable, Cloneable, Iterable<YaegerEntity>, Collection<YaegerEntity>, List<YaegerEntity>, RandomAccess, SequencedCollection<YaegerEntity>

public abstract class TileMap extends EntitySupplier implements Anchorable, Activatable
A 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:
  • Constructor Details

    • TileMap

      protected TileMap()
      Create a new TileMap that takes up the full width and height of the YaegerScene.
    • TileMap

      protected TileMap(Coordinate2D location, Size size)
      Create a new TileMap with the given width and height, placed on the given x and y.
      Parameters:
      location - the Coordinate2D of the top-left corner of the TileMap
      size - the Size of the TileMap
  • Method Details

    • setupEntities

      public abstract void setupEntities()
      The lifecycle method setupEntities() should be used to add the instances of YaegerEntity that should be used in this TileMap.
    • defineMap

      public abstract int[][] defineMap()
      The lifecycle method defineMap() should be used to define the map that should be used. It is represented by a two-dimensional array of type int, where each cell represents an YaegerEntity 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}}
            
       
      will place three rows of seven entities. In this case there should be four Entities added through the addEntity(int, Class) method.
      Returns:
      The two-dimensional array representing the map.
    • addEntity

      public void addEntity(int identifier, Class<? extends YaegerEntity> entityClass)
      Add the Class of an SpriteEntity that can be used in this TileMap. Each added SpriteEntity Classmust have an identifier for reference from the map. This method should only be called from the lifecycle method setupEntities().
      Parameters:
      identifier - the identifier as an int to be used from the map
      entityClass - the Class of a subclass of YaegerEntity to be used for the given identifier. Note that this YaegerEntity should have a constructor that accepts exactly two parameters. The first one should be a Coordinate2D and the second one a Size. If such a constructor is not present, an YaegerEngineException will be thrown.
    • addEntity

      public <C> void addEntity(int identifier, Class<? extends YaegerEntity> entityClass, C configuration)
      Add the Class of an SpriteEntity that can be used in this TileMap. Each added SpriteEntity Classmust have an identifier for reference from the map. This method should only be called from the lifecycle method setupEntities().
      Type Parameters:
      C - the type of the configuration
      Parameters:
      identifier - the identifier as an int to be used from the map
      entityClass - the Class of a subclass of YaegerEntity to be used for the given identifier. Note that this YaegerEntity should have a constructor that accepts exactly two parameters. The first one should be a Coordinate2D and the second one a Size. If such a constructor is not present, an YaegerEngineException will be thrown.
      configuration - an instance of type TileMap that is passed to the constructor of the created instance of YaegerEntity 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 interface Activatable
    • setAnchorPoint

      public void setAnchorPoint(AnchorPoint anchorPoint)
      Description copied from interface: Anchorable
      Set the AnchorPoint of this Placeable. The AnchorPoint can be used for aligning the YaegerEntity, and will be used to set the given x, y-coordinate. By default, a Placeable will use the top-left as its anchor-point.
      Specified by:
      setAnchorPoint in interface Anchorable
      Parameters:
      anchorPoint - the AnchorPoint of this YaegerEntity
    • getAnchorPoint

      public AnchorPoint getAnchorPoint()
      Description copied from interface: Anchorable
      Return the AnchorPoint of this Placeable.
      Specified by:
      getAnchorPoint in interface Anchorable
      Returns:
      the AnchorPoint of this Placeable
    • setTileFactory

      @Inject public void setTileFactory(TileFactory tileFactory)
      Set the TileFactory to be used.
      Parameters:
      tileFactory - an instance of TileFactory
    • getInstanceMap

      public YaegerEntity[][] getInstanceMap()
      Return a two-dimensional array of instances of YaegerEntity that contains the instances created by this TileMap. This way, this TileMap 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 calling YaegerEntity.remove(), it will also be removed from this TileMap, and no longer accessible through this method.

      Returns:
      a two-dimensional array that contains all instances of YaegerEntity created by this TileMap
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Collection<YaegerEntity>
      Specified by:
      equals in interface List<YaegerEntity>
      Overrides:
      equals in class EntitySupplier
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<YaegerEntity>
      Specified by:
      hashCode in interface List<YaegerEntity>
      Overrides:
      hashCode in class EntitySupplier