Class SprinklerComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.placeables.SprinklerComponent
- All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.badlogic.gdx.math.Vector2[]
A sprinklers area of effect to water, aoe is circular with radius of 2.protected boolean
Indicates if the 'sprinkler' is actually just a pump. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addWaterAnimator
(Entity animator) void
Sets powered status and texture 'orientation' based off the adjacent sprinklers.void
create()
Called when the entity is created and registered.protected boolean
finds a path to a pump, returns true if path found, false otherwise.protected Entity[]
Getter for adj entity listprotected boolean
Allows other sprinklers to query if this sprinkler has power.boolean
getPump()
Returns true if this sprinkler is a pump.void
Called via ConnectedEntityComponent's "reconfigure" trigger - This trigger is called when a new sprinkler is placed in this sprinklers' vicinity.protected void
setPower
(boolean state) Allows other sprinklers to set the power of this sprinkler.void
setPump()
Sets this sprinkler to be a pump.protected void
setTexture
(boolean powerStatus, byte orientation) Helper method to set the texture of this sprinkler, using a given power status and orientationprotected void
sprinkle()
Waters plants to the ideal amount within the aoe.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, read, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update, write
-
Field Details
-
pump
protected boolean pumpIndicates if the 'sprinkler' is actually just a pump. A pump is a sprinkler that doesn't update or sprinkle but is powered. -
aoe
protected com.badlogic.gdx.math.Vector2[] aoeA sprinklers area of effect to water, aoe is circular with radius of 2.
-
-
Constructor Details
-
SprinklerComponent
public SprinklerComponent()
-
-
Method Details
-
create
public void create()Called when the entity is created and registered. Initial logic such as calls to GetComponent should be made here, not in the constructor which is called before an entity is finished. -
getPowered
protected boolean getPowered()Allows other sprinklers to query if this sprinkler has power.- Returns:
- powered status
-
setPower
protected void setPower(boolean state) Allows other sprinklers to set the power of this sprinkler. -
setPump
public void setPump()Sets this sprinkler to be a pump. Should only be called in PlaceableFactory. -
getPump
public boolean getPump()Returns true if this sprinkler is a pump.- Returns:
- pump truth value
-
getAdjList
Getter for adj entity list- Returns:
- array of adj entities
-
configSprinkler
public void configSprinkler()Sets powered status and texture 'orientation' based off the adjacent sprinklers. - A power source is either a pump or a powered sprinkler. - A texture is selected for this sprinkler based on the surrounding sprinklers, this illustrates to the player that these sprinklers are connected - like pipes. -
setTexture
protected void setTexture(boolean powerStatus, byte orientation) Helper method to set the texture of this sprinkler, using a given power status and orientation- Parameters:
powerStatus
- powered status of sprinkler, used for texture selectionorientation
- orientation of sprinkler based off of adjacent sprinklers.
-
reConfigure
public void reConfigure()Called via ConnectedEntityComponent's "reconfigure" trigger - This trigger is called when a new sprinkler is placed in this sprinklers' vicinity. Re-configures using pathfinding (see findPump() and notifyConnected() methods). -
findPump
finds a path to a pump, returns true if path found, false otherwise.- Parameters:
calling
- the sprinkler calling.- Returns:
- truth value of weather we found a path to a pump or not.
-
sprinkle
protected void sprinkle()Waters plants to the ideal amount within the aoe. The aoe is relevant to this sprinklers position and looks like: 2 tiles: above, below, left, right. -
addWaterAnimator
-