Class UGS

java.lang.Object
com.deco2800.game.entities.UGS

public class UGS extends Object
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
    Constructor
    Description
    UGS()
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(com.badlogic.gdx.math.GridPoint2 coordinate, Tile tile)
    Adds a new entry to the UGS
    void
     
    void
    change(String key, Tile newTile)
     
    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
    dispose(Entity toRemove)
    This function is to be called anytime you
    static String
    generateCoordinate(int x, int y)
    Generates a coordinate given an x and y value
    void
    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 key
    getEntity(com.badlogic.gdx.math.GridPoint2 coordinate)
    Takes a String and returns the associated tile's entity or null if there is none
    Returns an entity or null found in the ugs by name of that entity
     
     
    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
    getTile(String coordinate)
     
    getTileType(com.badlogic.gdx.math.GridPoint2 coordinate)
    Takes a String (concatenated x,y value) and returns the associated tile's type
    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.
    Returns a copy of the UGS for testing purposes
    void
    Removes an entity from the hashmap by name
    setEntity(com.badlogic.gdx.math.GridPoint2 coordinate, Entity entity, String entityName)
    Takes a String and Entity, and sets the corresponding tile's Entity parameter
    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.
    void
    setTileType(com.badlogic.gdx.math.GridPoint2 coordinate, String tileType)
    Takes a String and Entity, and sets the corresponding tile's tileType parameter

    Methods inherited from class java.lang.Object

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

    • UGS

      public UGS()
  • Method Details

    • addStructure

      public void addStructure(Entity e)
    • getStructures

      public ArrayList<Entity> getStructures()
    • getTileType

      public String getTileType(com.badlogic.gdx.math.GridPoint2 coordinate)
      Takes a String (concatenated x,y value) and returns the associated tile's type
      Parameters:
      coordinate -
      Returns:
      String
    • getEntity

      public Entity getEntity(com.badlogic.gdx.math.GridPoint2 coordinate)
      Takes a String and returns the associated tile's entity or null if there is none
      Parameters:
      coordinate -
      Returns:
      Entity or NULL
    • removeEntity

      public void removeEntity(String name)
      Removes an entity from the hashmap by name
      Parameters:
      name - of the entity to remove
    • getStringByEntity

      public String getStringByEntity(Entity entity)
    • getEntityByName

      public Entity getEntityByName(String name)
      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 GridPoint2
      entityType - type of entity being checked
      Returns:
      map of all surrounding gridpoints and if they are full or empty
    • checkEntityPlacement

      public Boolean 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.
      Parameters:
      coordinate - x, y of the gridpoint in string form
      entityType - type of entity in string form
      Returns:
      true if the entity can spawn in a gridpoint else returns false
    • setTileType

      public void setTileType(com.badlogic.gdx.math.GridPoint2 coordinate, String tileType)
      Takes a String and Entity, and sets the corresponding tile's tileType parameter
      Parameters:
      coordinate -
      tileType -
    • getTile

      public Tile getTile(String coordinate)
    • add

      public void add(com.badlogic.gdx.math.GridPoint2 coordinate, Tile tile)
      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 - String
      entity - Entity
      dimensionX - Int
      dimensionY - Int
    • generateCoordinate

      public static String generateCoordinate(int x, int y)
      Generates a coordinate given an x and y value
      Parameters:
      x - integer
      y - integer
      Returns:
      String
    • dispose

      public void dispose(Entity toRemove)
      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 - String
      xDirection - Boolean
      yDirection - Boolean
    • generateUGS

      public void generateUGS()
      Generates a Mapsize x Mapsize sized grid and initialises a Tile object in each coordinate.
    • change

      public void change(String key, Tile newTile)
    • printUGS

      public HashMap<String,Tile> printUGS()
      Returns a copy of the UGS for testing purposes
      Returns:
      UGS
    • getClickedEntity

      public Entity 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