Class StaminaComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.player.StaminaComponent
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Called when the entity is created and registered.void
dispose()
Cancels the repeating stamina task when this component is disposed to prevent leaks.float
Returns the current stamina value.boolean
hasStamina
(float amount) Returns whether the player has enough stamina to perform the movement.void
setDashing
(boolean dashing) Set if the player is dashingvoid
setGrounded
(boolean grounded) Set if the player is groundedvoid
setInfiniteStamina
(boolean infiniteStamina) Updates the infiniteStamina parametervoid
setMoving
(boolean moving) Set if the player is movingvoid
setSprinting
(boolean sprinting) Set if the player is sprintingvoid
setStamina
(float value) Sets the current stamina value, clamped between 0 and MAX_STAMINA.boolean
trySpend
(float amount) Attempt to execute a movement.Methods inherited from class com.csse3200.game.components.Component
earlyUpdate, getEntity, getPrio, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
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. -
dispose
public void dispose()Cancels the repeating stamina task when this component is disposed to prevent leaks. -
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
-