Skip to content

Player Stamina

Anson Chan edited this page Sep 15, 2021 · 6 revisions

Description

Player stamina is a combat statistic component which determines whether the player is able to activate sprinting. At spawn, players have a full stamina level of 100. When players begin sprinting by holding the left SHIFT key, stamina begins to decrease at a steady rate until the user releases the SHIFT key or the stamina has reached zero. When the user releases the SHIFT key, the player stops sprinting and stamina level is regenerated. The rate of stamina regeneration is half the rate of stamina depletion.

The player’s stamina is represented in both text and animation format. The text value and the stamina bar update according to the player’s actual stamina value. A retro themed bar has been designed to use as the stamina bar. The fill of the bar changes depending on player’s stamina value, sliding left when stamina decreases and right when stamina increases.

Key Components

  • CombatStatsComponent : This component is responsible for storing, setting and updating the player stamina value.
  • PlayerStatsDisplay : This component extends the UIComponent class. It is responsible for drawing and updating the table containing the UI for the player stamina value and the stamina bar.
  • PlayerStaminaBar : This component extends the ProgressBar class. It is responsible for drawing the visual representation of the player stamina bar.

Operation

The initial player stamina value is specified in the player.json file. For performance purposes, the initial stamina value is set to 500. To create a more user-friendly experience, the visual display of the stamina value is 1/5 of the actual stamina value. For example, at game spawn, the actual stamina value is 500 but users will see 100.

When a new player entity is created in PlayerFactory, the initial player stamina value in the json file is passed into CombatStatsComponent. Within CombatStatsComponent, player stamina is set through the setStamina method, which ensures the stamina value does not exceed its upper and lower bounds.

When users hold/release the left SHIFT key, KeyboardPlayerInputComponent triggers the “run” or “stop_running” event. Within PlayerActions, it listens for the “run” or “stop_running” event. These events trigger the “change_stamina” event, where stamina is decreased by 2 when sprinting and increases by 1 when not sprinting. Within CombatStatsComponent, it listens for the “change_stamina” event and calls the changeStamina method to add/subtract the current stamina by the desired value.

The player stamina is displayed in the game UI through PlayerStatsDisplay, where a table is drawn at the top left corner of the game screen to display the stamina value and the stamina bar. A PlayerStaminaBar object is created to draw the animation for the player stamina bar. Whenever the stamina value is changed, CombatStatsComponent triggers the event “update_stamina”, which is listened by PlayerStatsDisplay to call the method updatePlayerStaminaUI. This method updates the value displayed in the stamina text UI and changes the value of the stamina bar.

Visual Representation

The player’s stamina is represented by the pink filling in the stamina bar. When player stamina is full, the pink filling extends the stamina bar. When stamina level is not full, the pink filling slides to the left and the purple background of the stamina bar is visible.

Stamina Bar

Full Stamina Half Stamina Zero Stamina

Future Changes

When boost items that affect stamina such as energy drinks are implemented in the future. The player stamina will change according to the properties of those boost items. For example, drinking energy drink might instantly replenish player’s stamina. This will affect how the stamina values are updated and changes will have to be made to the code implementation.

Testing

The Junit tests for the stamina functionality is documented in Unit Testing for Player Stamina and Running

The Junit tests for the stamina functionality is documented in User testing has also been conducted to collect user feedback for the functionality and style of the stamina feature. Here are some of the main takeaways from the feedback:

  • The stamina decreases too quickly.
  • The stamina regenerates too quickly, making the game too easy.
  • The green section of the stamina bar blends into the background.
  • The new stamina bar matches well with the game theme and has good contrast with the background of the game.

Based on the feedback, we have made changes to the functionality and the UI of the stamina feature.

  • Since many users mentioned that the stamina decreases too quickly, we have increased the value of the stamina to 500 so that it takes more time to deplete the stamina. However, this actual value is divided by 5 in the UI to prevent user confusion.
  • The regeneration of stamina is slower than the depletion of stamina to increase game difficulty.
  • The original UI design of the stamina bar has been completed overhaul to match the overall game theme. The colours are changed from green/red to pink/purple to stand out from the background. A white frame has also been added to further introduce contrast.
Clone this wiki locally