Package com.deco2800.game.entities
Class UGS
java.lang.Object
com.deco2800.game.entities.UGS
Provides a global access point for entities to register themselves to the
UGS. This allows for
checking for collisions and preventing entities from moving on certain tiles.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Adds a new entry to the UGSvoid
void
checkEntityPlacement
(com.badlogic.gdx.math.GridPoint2 coordinate, String entityType) Takes a String entityType and String coordinate and decides if that type of enity can spawn at that coordinate.void
This function is to be called anytime youstatic String
generateCoordinate
(int x, int y) Generates a coordinate given an x and y valuevoid
Generates a Mapsize x Mapsize sized grid and initialises a Tile object in each coordinate.Looks up the entity in the UGS at the cursor position in grid coordinates as the keygetEntity
(com.badlogic.gdx.math.GridPoint2 coordinate) Takes a String and returns the associated tile's entity or null if there is nonegetEntityByName
(String name) Returns an entity or null found in the ugs by name of that entitygetStringByEntity
(Entity entity) getSurroundingTiles
(com.badlogic.gdx.math.GridPoint2 centerCoord, String entityType, int offset) Gets a map of all surrounding tiles and labels them as empty or fullgetTileType
(com.badlogic.gdx.math.GridPoint2 coordinate) Takes a String (concatenated x,y value) and returns the associated tile's typevoid
moveEntity
(Entity entity, com.badlogic.gdx.math.GridPoint2 currentPosition, float xDirection, float yDirection) --------------------Does not account for tile type-------------------- Checks whether an entity can move in the given direction, and returns True if the move was carried out correctly.printUGS()
Returns a copy of the UGS for testing purposesvoid
removeEntity
(String name) Removes an entity from the hashmap by nameTakes a String and Entity, and sets the corresponding tile's Entity parametervoid
setLargeEntity
(com.badlogic.gdx.math.GridPoint2 origin, Entity entity, int dimensionX, int dimensionY, String entityName) Function for setting / updating tiles for an entity whose size is greater than 1x1.void
setTileType
(com.badlogic.gdx.math.GridPoint2 coordinate, String tileType) Takes a String and Entity, and sets the corresponding tile's tileType parameter
-
Constructor Details
-
UGS
public UGS()
-
-
Method Details
-
addStructure
-
getStructures
-
getTileType
Takes a String (concatenated x,y value) and returns the associated tile's type- Parameters:
coordinate
-- Returns:
- String
-
getEntity
Takes a String and returns the associated tile's entity or null if there is none- Parameters:
coordinate
-- Returns:
- Entity or NULL
-
removeEntity
Removes an entity from the hashmap by name- Parameters:
name
- of the entity to remove
-
getStringByEntity
-
getEntityByName
Returns an entity or null found in the ugs by name of that entity- Parameters:
name
- of the entity to find- Returns:
- the entity found or null
-
setEntity
public Boolean setEntity(com.badlogic.gdx.math.GridPoint2 coordinate, Entity entity, String entityName) Takes a String and Entity, and sets the corresponding tile's Entity parameter- Parameters:
coordinate
-entity
- Entity
-
getSurroundingTiles
public HashMap<com.badlogic.gdx.math.GridPoint2,String> getSurroundingTiles(com.badlogic.gdx.math.GridPoint2 centerCoord, String entityType, int offset) Gets a map of all surrounding tiles and labels them as empty or full- Parameters:
centerCoord
- position of the entity in GridPoint2entityType
- type of entity being checked- Returns:
- map of all surrounding gridpoints and if they are full or empty
-
checkEntityPlacement
Takes a String entityType and String coordinate and decides if that type of enity can spawn at that coordinate.- Parameters:
coordinate
- x, y of the gridpoint in string formentityType
- type of entity in string form- Returns:
- true if the entity can spawn in a gridpoint else returns false
-
setTileType
Takes a String and Entity, and sets the corresponding tile's tileType parameter- Parameters:
coordinate
-tileType
-
-
getTile
-
add
Adds a new entry to the UGS- Parameters:
coordinate
-tile
-
-
setLargeEntity
public void setLargeEntity(com.badlogic.gdx.math.GridPoint2 origin, Entity entity, int dimensionX, int dimensionY, String entityName) Function for setting / updating tiles for an entity whose size is greater than 1x1. Function takes an x,y dimension and will set/update the coordinates within those dimensions from the x,y origin to contain the entity. e.g. origin is 1,0 dimensionX = 2 dimensionY = 2 _ _ _ _ _ _ |_|_|_| |_|x|x| |_|_|_| -> |_|x|x| |_|_|_| |_|_|_|- Parameters:
origin
- Stringentity
- EntitydimensionX
- IntdimensionY
- Int
-
generateCoordinate
Generates a coordinate given an x and y value- Parameters:
x
- integery
- integer- Returns:
- String
-
dispose
This function is to be called anytime you- Parameters:
toRemove
- the generated coordinate key that maps to the entity you want to remove
-
moveEntity
public void moveEntity(Entity entity, com.badlogic.gdx.math.GridPoint2 currentPosition, float xDirection, float yDirection) --------------------Does not account for tile type-------------------- Checks whether an entity can move in the given direction, and returns True if the move was carried out correctly. If the move can be carried out, removes the entity from the current tile and adds it to the new tile. Takes a coordinate string as the currentPosition, and a boolean for yDirection and xDirection. yDirection: True if moving up (i.e. pressing w key) else false for moving down (s key) xDirection: True if moving to the right (i.e. pressing d key ) else false for moving to the left (a key) E.g. currentPosition: "3,3" yDirection: True xDirection: False Moves from 3,3 -> "2,2" {x-1, y-1}- Parameters:
currentPosition
- StringxDirection
- BooleanyDirection
- Boolean
-
generateUGS
public void generateUGS()Generates a Mapsize x Mapsize sized grid and initialises a Tile object in each coordinate. -
change
-
printUGS
Returns a copy of the UGS for testing purposes- Returns:
- UGS
-
getClickedEntity
Looks up the entity in the UGS at the cursor position in grid coordinates as the key- Returns:
- entity in the grid coordinate the cursor is in
-