CombatStatsDisplay - UQcsse3200/2024-studio-2 GitHub Wiki
Combat Stats Display
Overview
The CombatStatsDisplay
is a crucial component of the game's combat system. It extends UIComponent
and is responsible for displaying and updating the stats of both the player and enemy during one-on-one battles on the Combat Screen.
Key Features:
- Displays player stats: health, hunger, and experience
- Displays enemy stats: health, and hunger
- Updates stats bars based on combat actions
- Manages status effects UI
Key Changes
- Removal of Stats Table: The Stats Table has been removed as player and enemy entities can now be spawned directly on the Combat Screen.
- Addition of Statistics Bars: Player and enemy statistics bars are now displayed on the game screen.
- Integration of Dialogue Boxes: Combat is now illustrated using the Dialogue Box Service, enhancing the player experience.
- Implementation of Status Effects: New UI components reflect status effects caused by boss NPCs.
For more details on recent changes, see:
Key Components
Statistics Bars Animation
Statistics bars for players and enemies are initialized and handled within this UI Component. For more information, see Animation of Stats Bars.
Player Status Reflection
The statistics bars in the Combat Screen reflect any changes from the initial starting statistics of the players experienced while roaming the main game screen.
Pixel-Art Designs
The game uses hand-designed pixel art for stat bars and status effect images, created by Team 11 (UI Stats) and Team 10 respectively. These designs match the game's visual style and integrate seamlessly with the pixelated world.
Usage
The CombatStatsDisplay
is instantiated and added to a UI entity in the createUI()
method of CombatScreen.java
:
private void createUI() {
Entity ui = new Entity();
ui.addComponent(new InputDecorator(stage, 10))
.addComponent(manager)
.addComponent(new CombatActions(this.game, manager, oldScreen, oldScreenServices))
.addComponent(new CombatExitDisplay())
.addComponent(new CombatStatsDisplay(playerCombatStats, enemyCombatStats))
// ... other components
ServiceLocator.getEntityService().register(ui);
}
Class Structure
CombatStatsDisplay
classDiagram
UIComponent <|-- CombatStatsDisplay
CombatStatsDisplay --> CombatStatsComponent
CombatStatsDisplay --> Image
CombatStatsDisplay --> Label
CombatStatsDisplay --> Animation
CombatStatsDisplay --> Table
class CombatStatsDisplay {
-CombatStatsComponent playerStats
-CombatStatsComponent enemyStats
-Image playerHealthImage
-Image playerHungerImage
-Image enemyHealthImage
-Image enemyHungerImage
-Image xpImage
-Label playerHealthLabel
-Label playerHungerLabel
-Label enemyHealthLabel
-Label enemyHungerLabel
-Label experienceLabel
-Label statusEffectLabel
-Animation<TextureRegion> playerHealthBarAnimation
-Animation<TextureRegion> enemyHealthBarAnimation
-Animation<TextureRegion> playerHungerBarAnimation
-Animation<TextureRegion> enemyHungerBarAnimation
-Animation<TextureRegion> playerExperienceBarAnimation
-float barImageWidth
-float barImageHeight
-int totalFrames
-Table hoverTextTable;
-Label hoverTextLabel;
-Image backgroundImage;
+create()
-initialisePlayerStatsBars()
-initialiseEnemyStatsBars()
-initBarAnimations()
-setNewFrame(int, Animation<TextureRegion>, Image)
-addActors()
+updateHealthUI(CombatStatsComponent, CombatStatsComponent)
+updatePlayerExperienceUI(CombatStatsComponent)
+updateHungerUI(CombatStatsComponent, CombatStatsComponent)
+updateStatusEffectUI(CombatStatsComponent.StatusEffect statusEffect)
+draw(SpriteBatch)
+dispose()
-removeStatusUI()
-createTextForHints()
-createBackgroundForHints()
-setTextForStatusEffectHint()
}
-
Attributes:
playerStats
: The current stats of the player, containing all the stats of the player entity and methods to access/edit them.playerStats
: The current stats of the enemy the player is in combat with, containing all the stats of the player entity and methods to access/edit them.playerHealthImage
: The initial image of the health bar to be displayed on screen (full health at this point).playerHungerImage
: The initial image of the hunger bar to be displayed on screen (full hunger at this point).enemyHealthImage
: The initial image of the enemy health bar to be displayed on screen (full health).enemyHungerImage
: The initial image of the enemy hunger bar to be displayed on screen (full health).xpImage
: The initial image of the player experience bar to be displayed on screen (no experience at this point).playerHealthLabel
: A label displaying the player's current health points.playerHungerLabel
: A label displaying the player's current hunger points.enemyHealthLabel
: A label displaying the enemy's current health points.enemyHungerLabel
: A label displaying the enemy's current health points.statusEffectLabel
: A label displaying the player's current status.experienceLabel
: A label displaying the player's current experience points.playerHealthBarAnimation
: The animation being used to update the frame of the health bar on the screen for the playerenemyHealthBarAnimation
: The animation being used to update the frame of the health bar on the screen for the enemyplayerHungerBarAnimation
: The animation being used to update the frame of the hunger bar on the screen for the playerenemyHungerBarAnimation
: The animation being used to update the frame of the hunger bar on the screen for the enemyplayerExperienceBarAnimation
: The animation being used to update the frame of the experience bar on the screen for the playerbarImageWidth
: The width of the health bar, used to resize every other bar to matchbarImageHeight
: The height of the health bar, used to resize every other bar to matchtotalFrames
: The total number of frames each bar has and usedhoverTextTable
: The table being used to display descriptionshoverTextLabel
: The table being
-
Methods (related to displaying the Combat Stats):
create()
: Initialises listeners for function calls made in CombatActions as well as adding actors to the stage.initialisePlayerStatsBars()
: Initialises all of the labels and images related to the player, adding them to a table that will be added by addActors(). This table is returned.initialiseEnemyStatsBars()
: Initialises all of the labels and images related to the enemy, adding them to a table that will be added by addActors(). This table is returned.initBarAnimations()
: Initialises all of the animations for the stats bars of both the player and enemy.setNewFrame(int frameIndex, Animation<TextureRegion> statBarAnimation, Image statBar)
: Updates the current frame that is being displayed on the combat screen using the provided index to locate the correct frame, and the animation and image to replace the correct bar on the screen.addActors()
: Adds all the images and labels to the Combat Screen, as well as initialising the animations (calls initialisePlayerStatsBars, initialiseEnemyStatsBars, initBarAnimations).updateHealthUI(CombatStatsComponent playerStats, CombatStatsComponent enemyStats)
: Updates the frame and label of both the player and enemy health bars being shown on screen, based on the stats components being provided.updatePlayerExperienceUI(CombatStatsComponent playerStats)
: Updates the frame and label of the player experience bar being shown on screen, based on the stats components being provided.updateHungerUI(CombatStatsComponent playerStats, CombatStatsComponent enemyStats)
: Updates the frame and label of the player hunger bars being shown on screen, based on the stats components being provided.draw()
: Inherited method from UIComponent, currently unused.dispose()
: Used to clear all of the images, animations and labels once the CombatScreen is no longer currently in use.
Sequence Diagram: Updating Health Bar on Attack
sequenceDiagram
participant CA as CombatActions
participant CSD as CombatStatsDisplay
participant PS as PlayerStats
participant ES as EnemyStats
participant HB as HealthBar
participant HL as HealthLabel
CA->>CSD: onAttack event
CSD->>PS: getHealth()
PS-->>CSD: currentHealth
CSD->>ES: getHealth()
ES-->>CSD: currentHealth
CSD->>HB: setNewFrame(frameIndex, animation, image)
CSD->>HL: setText(newHealthText)
This diagram illustrates the process of updating the health bar during an attack action.
Related Components
The CombatStatsDisplay
interacts with several other components in the game:
UIComponent
: The base class thatCombatStatsDisplay
extends from.CombatStatsComponent
: Provides the actual stat values for players and enemies.Image
: Used to display the visual representations of stat bars.Label
: Used to display numerical stat values.Animation
: Handles the animation of stat bars.Table
: Used for layout of UI elements.
For a more detailed view of these relationships, refer to the class diagram above.