Class MapService

java.lang.Object
com.deco2800.game.map.MapService

public class MapService extends Object
Stores all game entity positions.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addIslandTile(int x, int y)
    Add an island tile position to the MapService
    Map<MapComponent,List<com.badlogic.gdx.math.GridPoint2>>
    Returns a map of all entities to the positions they occupy.
    getEntityAt(com.badlogic.gdx.math.GridPoint2 position)
    Gets the entity at the given position.
    Map<com.badlogic.gdx.math.GridPoint2,MapComponent>
    Returns a map of positions to entities.
    List<com.badlogic.gdx.math.GridPoint2>
    Returns a list of island tile positions.
    Returns all registered entities.
    List<com.badlogic.gdx.math.GridPoint2>
    getPath(com.badlogic.gdx.math.GridPoint2 start, com.badlogic.gdx.math.GridPoint2 goal)
    Finds a path between two points using BFS search.
    List<com.badlogic.gdx.math.GridPoint2>
    getPath(MapComponent comp, com.badlogic.gdx.math.GridPoint2 goal)
    Returns the shortest path to a goal, or throws an exception if the goal is invalid.
    boolean
    isOccupied(com.badlogic.gdx.math.GridPoint2 position)
    Returns true if position is occupied by an entity, else false.
    void
    Registers an entity with the MapService.
    void
    registerMapDetails(int height, int width, float tileSize)
    Registers relevant map details with MapService
    static com.badlogic.gdx.math.Vector2
    tileToWorldPosition(int x, int y)
     
    static com.badlogic.gdx.math.Vector2
    tileToWorldPosition(com.badlogic.gdx.math.GridPoint2 tilePos)
     
    void
    Remove entity from the MapService.
    void
    Updates the MapService's understanding of an entity's current position.
    static com.badlogic.gdx.math.GridPoint2
    worldToTile(float worldX, float worldY)
    Converts a world point to a position on the tile map
    static com.badlogic.gdx.math.GridPoint2
    worldToTile(float tileSize, float worldX, float worldY)
    Converts a world point to a position on the tile map
    static com.badlogic.gdx.math.GridPoint2
    worldToTile(com.badlogic.gdx.math.Vector2 position)
    Converts a world point to a position on the tile map

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MapService

      public MapService()
  • Method Details

    • getEntityOccupiedPositions

      public Map<com.badlogic.gdx.math.GridPoint2,MapComponent> getEntityOccupiedPositions()
      Returns a map of positions to entities.
      Returns:
      map of positions to entities.
    • getMapComponents

      public List<MapComponent> getMapComponents()
      Returns all registered entities.
      Returns:
      all registered entities
    • update

      public void update(MapComponent comp)
      Updates the MapService's understanding of an entity's current position.
      Parameters:
      comp - the entity whose position is to be updated.
    • register

      public void register(MapComponent comp)
      Registers an entity with the MapService.
      Parameters:
      comp - entity to register.
    • unregister

      public void unregister(MapComponent comp)
      Remove entity from the MapService.
      Parameters:
      comp - the entity to remove.
    • getPath

      public List<com.badlogic.gdx.math.GridPoint2> getPath(MapComponent comp, com.badlogic.gdx.math.GridPoint2 goal) throws OutOfBoundsException, OccupiedTileException
      Returns the shortest path to a goal, or throws an exception if the goal is invalid.
      Parameters:
      comp - the entity to find a path for.
      goal - the goal positions
      Returns:
      a list of tile positions
      Throws:
      OutOfBoundsException - if the tile is not a land tile
      OccupiedTileException - if the goal position is occupied by another entity
    • getPath

      public List<com.badlogic.gdx.math.GridPoint2> getPath(com.badlogic.gdx.math.GridPoint2 start, com.badlogic.gdx.math.GridPoint2 goal)
      Finds a path between two points using BFS search.
      Parameters:
      start - the starting position
      goal - the end position
      Returns:
      a list of positions indicating the shortest path
    • registerMapDetails

      public void registerMapDetails(int height, int width, float tileSize)
      Registers relevant map details with MapService
      Parameters:
      height - height of map
      width - width of map
      tileSize - size of a tile
    • addIslandTile

      public void addIslandTile(int x, int y)
      Add an island tile position to the MapService
      Parameters:
      x - x-coordinate of tile
      y - y-coordinate of tile
    • getIslandTiles

      public List<com.badlogic.gdx.math.GridPoint2> getIslandTiles()
      Returns a list of island tile positions.
      Returns:
      list of island tile positions
    • isOccupied

      public boolean isOccupied(com.badlogic.gdx.math.GridPoint2 position)
      Returns true if position is occupied by an entity, else false.
      Parameters:
      position - to check if occupied
      Returns:
      true if occupied, else false
    • getEntityAt

      public Entity getEntityAt(com.badlogic.gdx.math.GridPoint2 position) throws NoEntityException
      Gets the entity at the given position.
      Throws:
      NoEntityException - if there is no entity
    • getAllEntityPositions

      public Map<MapComponent,List<com.badlogic.gdx.math.GridPoint2>> getAllEntityPositions()
      Returns a map of all entities to the positions they occupy.
      Returns:
      map of MapComponent to list of occupied positions
    • worldToTile

      public static com.badlogic.gdx.math.GridPoint2 worldToTile(com.badlogic.gdx.math.Vector2 position)
      Converts a world point to a position on the tile map
      Parameters:
      position - Vector2 position to convert
      Returns:
      position of the world point on the tile map
    • worldToTile

      public static com.badlogic.gdx.math.GridPoint2 worldToTile(float worldX, float worldY)
      Converts a world point to a position on the tile map
      Parameters:
      worldX - world y position of an entity
      worldY - world y position of an entity
      Returns:
      position of the world point on the tile map
    • worldToTile

      public static com.badlogic.gdx.math.GridPoint2 worldToTile(float tileSize, float worldX, float worldY)
      Converts a world point to a position on the tile map
      Parameters:
      tileSize - tileSize returned by TerrainComponent of map
      worldX - world y position of an entity
      worldY - world y position of an entity
      Returns:
      position of the world point on the tile map
    • tileToWorldPosition

      public static com.badlogic.gdx.math.Vector2 tileToWorldPosition(com.badlogic.gdx.math.GridPoint2 tilePos)
    • tileToWorldPosition

      public static com.badlogic.gdx.math.Vector2 tileToWorldPosition(int x, int y)