Package com.deco2800.game.map
Class MapService
java.lang.Object
com.deco2800.game.map.MapService
Stores all game entity positions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addIslandTile
(int x, int y) Add an island tile position to the MapServiceMap<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
register
(MapComponent comp) Registers an entity with the MapService.void
registerMapDetails
(int height, int width, float tileSize) Registers relevant map details with MapServicestatic com.badlogic.gdx.math.Vector2
tileToWorldPosition
(int x, int y) static com.badlogic.gdx.math.Vector2
tileToWorldPosition
(com.badlogic.gdx.math.GridPoint2 tilePos) void
unregister
(MapComponent comp) Remove entity from the MapService.void
update
(MapComponent comp) 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 mapstatic com.badlogic.gdx.math.GridPoint2
worldToTile
(float tileSize, float worldX, float worldY) Converts a world point to a position on the tile mapstatic com.badlogic.gdx.math.GridPoint2
worldToTile
(com.badlogic.gdx.math.Vector2 position) Converts a world point to a position on the tile map
-
Constructor Details
-
MapService
public MapService()
-
-
Method Details
-
getEntityOccupiedPositions
Returns a map of positions to entities.- Returns:
- map of positions to entities.
-
getMapComponents
Returns all registered entities.- Returns:
- all registered entities
-
update
Updates the MapService's understanding of an entity's current position.- Parameters:
comp
- the entity whose position is to be updated.
-
register
Registers an entity with the MapService.- Parameters:
comp
- entity to register.
-
unregister
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 tileOccupiedTileException
- 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 positiongoal
- 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 mapwidth
- width of maptileSize
- 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 tiley
- y-coordinate of tile
-
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
Gets the entity at the given position.- Throws:
NoEntityException
- if there is no entity
-
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 entityworldY
- 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 mapworldX
- world y position of an entityworldY
- 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)
-