Package com.deco2800.game.entities
Class StructureService
java.lang.Object
com.deco2800.game.entities.EntityService
com.deco2800.game.entities.StructureService
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.
-
Field Summary
Fields inherited from class com.deco2800.game.entities.EntityService
toDestroyEntities
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Boolean
buildStructure
(String structureName, com.badlogic.gdx.math.GridPoint2 gridPos) Builds a structure at specific location, gridPos.static void
buildTempStructure
(String name) Builds a structure and locks it to the mouse as the user decides where to build itstatic void
Clear the coloured visual tiles by disposing of themvoid
dispose()
Dispose all entities.static void
drawVisualFeedback
(com.badlogic.gdx.math.GridPoint2 centerCoord, String entityType) Draw the coloured tiles around a structure to show the player where they can build a structureReturns all registered entitiesReturns the last registered entitygetNamedEntity
(String name) Returns a registered named entitystatic int
get the orientation of the structure being built (facing forward or facing right)static Boolean
gets the building temp entity statestatic String
gets the temp building namevoid
Register a new entity with the entity service.void
registerNamed
(String name, Entity entity) Registers an entity with a name, so it can be found laterstatic void
Rotate the current temp structureSellBuilding
(String buildingName, com.badlogic.gdx.math.GridPoint2 entityCords) void
setTempBuildState
(Boolean state) Set the building temp entity statestatic void
setUiPopUp
(int screenX, int screenY) static void
toggle the structure orientation from 0 to 1 or from 1 to 0void
unregister
(Entity entity) Unregister an entity with the entity service.void
update()
Update all registered entities.Methods inherited from class com.deco2800.game.entities.EntityService
addEntity, addToDestroyEntities, findClosestEnemy, findClosestEntity, getCurrentWorldStep, getEnemyEntities, getEntities, getToDestroyEntities, removeNamedEntity, setCurrentWorldStep, setDestroyEntire, unregisterNamed
-
Constructor Details
-
StructureService
public StructureService()
-
-
Method Details
-
register
Register a new entity with the entity service. The entity will be created and start updating.- Overrides:
register
in classEntityService
- Parameters:
entity
- new entity.
-
registerNamed
Registers an entity with a name, so it can be found later- Overrides:
registerNamed
in classEntityService
- Parameters:
name
- the name to register it as (must be unique or will overwrite)entity
- the entity to register
-
getNamedEntity
Returns a registered named entity- Overrides:
getNamedEntity
in classEntityService
- Parameters:
name
- the name the entity was registered as- Returns:
- the registered entity or null
-
getLastEntity
Returns the last registered entity- Overrides:
getLastEntity
in classEntityService
- Returns:
- the last registered entity or null
-
getAllNamedEntities
Returns all registered entities- Overrides:
getAllNamedEntities
in classEntityService
- Returns:
- all registered entities or null
-
unregister
Unregister an entity with the entity service. The entity will be removed and stop updating.- Overrides:
unregister
in classEntityService
- Parameters:
entity
- entity to be removed.
-
update
public void update()Update all registered entities. Should only be called from the main game loop.- Overrides:
update
in classEntityService
-
dispose
public void dispose()Dispose all entities.- Overrides:
dispose
in classEntityService
-
buildStructure
public static Boolean buildStructure(String structureName, com.badlogic.gdx.math.GridPoint2 gridPos) Builds a structure at specific location, gridPos. the type of structure built is determined by the specific structure name, structureName.- Parameters:
structureName
- name of the structure to build (also type of structure)gridPos
- location of where the structure is to be built- Returns:
- true if building was build successfully, false otherwise
-
getTempBuildState
gets the building temp entity state- Returns:
- True if building a building from the inventory or False if not building a building from the inventory
-
getTempEntityName
gets the temp building name- Returns:
- name of the temp entity
-
setTempBuildState
Set the building temp entity state- Parameters:
state
- state to set the buildingTempEntity state to.
-
buildTempStructure
Builds a structure and locks it to the mouse as the user decides where to build it- Parameters:
name
- of the tempStructureEntity
-
drawVisualFeedback
public static void drawVisualFeedback(com.badlogic.gdx.math.GridPoint2 centerCoord, String entityType) Draw the coloured tiles around a structure to show the player where they can build a structure- Parameters:
centerCoord
- location of the structure in gridPoint2entityType
- type of entity being checked
-
clearVisualTiles
public static void clearVisualTiles()Clear the coloured visual tiles by disposing of them -
rotateTempStructure
public static void rotateTempStructure()Rotate the current temp structure -
getStructureOrientation
public static int getStructureOrientation()get the orientation of the structure being built (facing forward or facing right)- Returns:
-
toggleStructureOrientation
public static void toggleStructureOrientation()toggle the structure orientation from 0 to 1 or from 1 to 0 -
setUiPopUp
public static void setUiPopUp(int screenX, int screenY) -
SellBuilding
-