Class EntityService

java.lang.Object
com.csse3200.game.entities.EntityService

public class EntityService extends Object
Provides a global access point for entities to register themselves. This allows for iterating over entities to perform updates each loop. All game entities should be registered here. Avoid adding additional state here! Global access is often the easy but incorrect answer to sharing data.
  • Constructor Details

    • EntityService

      public EntityService()
  • Method Details

    • removeEntity

      public static void removeEntity(Entity clickedEntity)
    • register

      public void register(Entity entity)
      Register a new entity with the entity service. The entity will be created and start updating.
      Parameters:
      entity - new entity.
    • unregister

      public void unregister(Entity entity)
      Unregister an entity with the entity service. The entity will be removed and stop updating.
      Parameters:
      entity - entity to be removed.
    • update

      public void update()
      Update all registered entities. Should only be called from the main game loop.
    • dispose

      public void dispose()
      Dispose all entities.
    • findEntityExistence

      public boolean findEntityExistence(int id)
      Find an entity by its ID, if it exists return true, else return false
      Parameters:
      id - id of entity to find
      Returns:
      boolean true if entity exists, false if not
    • getEntities

      public com.badlogic.gdx.utils.Array<Entity> getEntities()
      Get all entities
    • getNearbyEntities

      public com.badlogic.gdx.utils.Array<Entity> getNearbyEntities(Entity source, float radius)
      Get entities within a certain radius of a given entity.
      Parameters:
      source - The reference entity to check distance from.
      radius - The radius within which to fetch entities.
      Returns:
      An array containing entities within the given radius.
    • getEntitiesInLayer

      public com.badlogic.gdx.utils.Array<Entity> getEntitiesInLayer(Entity source, float radius, short layer)
      Get entities within a certain radius of a given entity.
      Parameters:
      source - The reference entity to check distance from.
      radius - The radius within which to fetch entities.
      layer - Desired layer for entities to be in
      Returns:
      An array containing entities within the given radius.
    • getClosestEntityOfLayer

      public Entity getClosestEntityOfLayer(Entity source, short layer)
      Returns the closest entity to the source of provided layer
      Parameters:
      source - source entity
      layer - layer for desired entity to be returned
      Returns:
      closest entity of correct layer
    • getEntityAtPosition

      public Entity getEntityAtPosition(float x, float y)
    • entitiesInTile

      public boolean entitiesInTile(int x_coord, int y_coord)
      Determine whether there are any entities within the given tile position (x and y range). Checks for out of bounds click location
      Parameters:
      x_coord - the top right x coordinate of the tile
      y_coord - the top right y coordinate of the tile
      Returns:
      true if the tile is occupied, false otherwise
    • getEntityAtPositionLayer

      public Entity getEntityAtPositionLayer(float x, float y, short layer)