Package com.csse3200.game.entities
Class EntityService
java.lang.Object
com.csse3200.game.entities.EntityService
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Dispose all entities.boolean
entitiesInTile
(int x_coord, int y_coord) Determine whether there are any entities within the given tile position (x and y range).boolean
findEntityExistence
(int id) Find an entity by its ID, if it exists return true, else return falsegetClosestEntityOfLayer
(Entity source, short layer) Returns the closest entity to the source of provided layercom.badlogic.gdx.utils.Array<Entity>
Get all entitiescom.badlogic.gdx.utils.Array<Entity>
getEntitiesInLayer
(Entity source, float radius, short layer) Get entities within a certain radius of a given entity.getEntityAtPosition
(float x, float y) getEntityAtPositionLayer
(float x, float y, short layer) com.badlogic.gdx.utils.Array<Entity>
getNearbyEntities
(Entity source, float radius) Get entities within a certain radius of a given entity.void
Register a new entity with the entity service.static void
removeEntity
(Entity clickedEntity) void
unregister
(Entity entity) Unregister an entity with the entity service.void
update()
Update all registered entities.
-
Constructor Details
-
EntityService
public EntityService()
-
-
Method Details
-
removeEntity
-
register
Register a new entity with the entity service. The entity will be created and start updating.- Parameters:
entity
- new entity.
-
unregister
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
Get all entities -
getNearbyEntities
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
Returns the closest entity to the source of provided layer- Parameters:
source
- source entitylayer
- layer for desired entity to be returned- Returns:
- closest entity of correct layer
-
getEntityAtPosition
-
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 tiley_coord
- the top right y coordinate of the tile- Returns:
- true if the tile is occupied, false otherwise
-
getEntityAtPositionLayer
-