Repository navigation
Stamina System
The Stamina System allows the player to manage a limited stamina resource while using specific movement abilities. Stamina is consumed when the player performs a double jump, dash, or slide and then regenerates over time.
The stamina value is displayed through the game's UI so that the player can monitor their remaining stamina.
- Stamina has a maximum value of 100.
- Double jumping consumes 10 stamina.
- Dashing consumes 20 stamina.
- Sliding consumes 15 stamina.
- Normal jumping does not consume stamina.
- Attacking does not consume stamina.
- Stamina cannot decrease below 0.
- The player cannot perform a stamina-consuming movement action when they do not have enough stamina.
- Stamina regenerates over time after stamina has been used.
- Stamina regenerates at a rate of 5 stamina per second.
- Stamina cannot regenerate above the maximum value of 100.
- The current stamina value is sent to the UI to update the stamina bar.
The StaminaComponent manages the player's stamina value and provides methods for:
- Getting the current stamina.
- Getting the maximum stamina.
- Checking whether the player has enough stamina for an action.
- Consuming stamina.
- Regenerating stamina.
- Setting the stamina value when loading saved game data.
- Accessing the stamina costs for double jumping, dashing, and sliding.
- Accessing the stamina regeneration rate.
The stamina system uses the following values:
| Property | Value |
|---|---|
| Maximum Stamina | 100 |
| Double Jump Cost | 10 |
| Dash Cost | 20 |
| Slide Cost | 15 |
| Regeneration Rate | 5 per second |
When stamina is consumed, the value is clamped to zero to prevent negative stamina values.
The PlatformerComponent integrates the stamina system with the player's jump functionality.
Normal jumps and wall jumps do not consume stamina.
When the player performs a double jump:
- The system checks whether the player has enough stamina.
- If sufficient stamina is available, the double jump is performed.
- 10 stamina is consumed.
- The double-jump state is updated.
If there is insufficient stamina, the double jump is not performed.
This ensures that stamina is only consumed for the additional jump rather than for normal or wall jumps.
The dash system checks the player's available stamina before performing a dash.
A successful dash consumes 20 stamina. If the player has less than the required stamina, the dash cannot be performed.
The existing dash movement behaviour and cooldown remain unchanged.
Attacks do not consume stamina.
Normal attacks, special attacks, and area attacks continue to use their existing combat functionality without checking or consuming stamina.
The existing attack damage, cooldowns, target selection, and other attack behaviour remain unchanged.
This allows the player to retain stamina for movement abilities that can be used to escape dangerous situations.
The slide system checks the player's available stamina when the slide begins.
A successful slide consumes 15 stamina. If the player does not have enough stamina, the slide is not performed.
Stamina is consumed once when the slide starts rather than continuously throughout the slide. The existing slide duration and movement behaviour remain unchanged.
The slide is triggered by the player's L-Shift input.
The current stamina value is sent through the entity event system using the updateStamina event.
The stamina display uses this value to update the stamina bar shown to the player.
The stamina UI is updated whenever the stamina value changes, including when stamina is consumed or regenerated.
Unit tests have been implemented for the StaminaComponent and the stamina-related player actions.
The tests cover:
- Initial stamina value.
- Maximum stamina value.
- Checking whether the player has sufficient stamina.
- Stamina consumption.
- Preventing stamina from going below zero.
- Double jump stamina cost.
- Dash stamina cost.
- Slide stamina cost.
- Stamina regeneration.
- Preventing regeneration from exceeding the maximum stamina.
- Stamina regeneration rate.
- Preventing stamina-consuming actions when insufficient stamina is available.
- Verifying that attacks do not consume stamina.
The stamina tests ensure that the stamina system behaves correctly while preserving the existing functionality of actions that do not require stamina.
The current stamina flow is:
- The player starts with 100 stamina.
- Normal jumping does not consume stamina.
- Double jumping consumes 10 stamina.
- Wall jumping does not consume stamina.
- Dashing consumes 20 stamina.
- Attacking does not consume stamina.
- Sliding using L-Shift consumes 15 stamina.
- Stamina cannot fall below 0.
- Stamina regenerates at 5 stamina per second.
- Regeneration stops when stamina reaches 100.
- Double jumping, dashing, and sliding are prevented when the player does not have enough stamina for the respective action.
- Normal jumping and wall jumping remain available without stamina.
- Normal attacks, special attacks, and area attacks remain available without stamina.
- The stamina UI is updated whenever the stamina value changes.
- Further balance stamina costs and regeneration values based on gameplay testing.
- Improve visual feedback when the player does not have enough stamina to perform an action.
- Improve the visual feedback associated with stamina regeneration and depletion.
- Add additional stamina-related gameplay mechanics if required by future game features.