Class StaminaComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.player.StaminaComponent

public class StaminaComponent extends Component
  • Constructor Details

    • StaminaComponent

      public StaminaComponent()
  • Method Details

    • create

      public void create()
      Description copied from class: Component
      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
    • dispose

      public void dispose()
      Cancels the repeating stamina task when this component is disposed to prevent leaks.
      Overrides:
      dispose in class Component
    • hasStamina

      public boolean hasStamina(float amount)
      Returns whether the player has enough stamina to perform the movement.
      Parameters:
      amount - the stamina cost
      Returns:
      if the player has sufficient stamina
    • trySpend

      public boolean trySpend(float amount)
      Attempt to execute a movement.
      Parameters:
      amount - the amount of stamina required.
      Returns:
      whether the movement can be completed.
    • getStamina

      public float getStamina()
      Returns the current stamina value.
      Returns:
      current stamina
    • setStamina

      public void setStamina(float value)
      Sets the current stamina value, clamped between 0 and MAX_STAMINA. Triggers a UI update if the integer value changes.
      Parameters:
      value - new stamina value
    • setInfiniteStamina

      public void setInfiniteStamina(boolean infiniteStamina)
      Updates the infiniteStamina parameter
      Parameters:
      infiniteStamina - whether the player should have infinite stamina.
    • setMoving

      public void setMoving(boolean moving)
      Set if the player is moving
    • setSprinting

      public void setSprinting(boolean sprinting)
      Set if the player is sprinting
    • setDashing

      public void setDashing(boolean dashing)
      Set if the player is dashing
    • setGrounded

      public void setGrounded(boolean grounded)
      Set if the player is grounded