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

    • saveCurrentArea

      public AreaEntityConfig saveCurrentArea()
    • getPlayer

      public Entity getPlayer()
      Gets the player entity in the EntityService
      Returns:
      Entity - the player entity, or null - no player found in EntityService
    • getEntitiesByComponent

      public List<Entity> getEntitiesByComponent(Class<? extends Component> componentClass)
      Gets all entities belonging to a specified component class.

      Example: getEntitiesByComponent(PowerupComponent.class) will return a list of all registered powerup entities.

      Parameters:
      componentClass - The component class to search for
      Returns:
      An array of entities who have the specified component
    • 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.
    • getCompanion

      public Entity getCompanion()