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

public class SprinklerComponent extends Component
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected 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.

    Fields inherited from class com.csse3200.game.components.Component

    enabled, entity
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    Sets powered status and texture 'orientation' based off the adjacent sprinklers.
    void
    Called when the entity is created and registered.
    protected boolean
    findPump(Entity calling)
    finds a path to a pump, returns true if path found, false otherwise.
    protected Entity[]
    Getter for adj entity list
    protected boolean
    Allows other sprinklers to query if this sprinkler has power.
    boolean
    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
    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 orientation
    protected void
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • pump

      protected boolean pump
      Indicates 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[] aoe
      A 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.
      Overrides:
      create in class Component
    • 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

      protected Entity[] 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 selection
      orientation - 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

      protected boolean findPump(Entity calling)
      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

      public void addWaterAnimator(Entity animator)