Class PlayerStatsDisplay
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.rendering.RenderComponent
com.csse3200.game.ui.UIComponent
com.csse3200.game.components.player.PlayerStatsDisplay
- All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable
,Renderable
,Comparable<Renderable>
A UI component for displaying player stats, such as health, hunger, and experience.
This component handles the creation, updating, and disposing
the player's stats on the screen.
-
Field Summary
FieldsModifier and TypeFieldDescriptionboolean
com.badlogic.gdx.scenes.scene2d.ui.Image
com.badlogic.gdx.scenes.scene2d.ui.Label
com.badlogic.gdx.scenes.scene2d.ui.Image
com.badlogic.gdx.scenes.scene2d.ui.Label
int
int
int
com.badlogic.gdx.graphics.g2d.TextureAtlas[]
int
com.badlogic.gdx.scenes.scene2d.ui.Image
Fields inherited from class com.csse3200.game.ui.UIComponent
skin, stage
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Initializes and adds actors (UI elements) to the stage.void
dispose()
Disposes of the resources used by the PlayerStatsDisplay component, including textures and labels.void
draw
(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Draw the renderable.void
Initializes the animations for the health, hunger, and experience bars.void
setNewFrame
(int frameIndex, com.badlogic.gdx.graphics.g2d.Animation<com.badlogic.gdx.graphics.g2d.TextureRegion> statBarAnimation, com.badlogic.gdx.scenes.scene2d.ui.Image statBar) Sets a new frame for a stat bar animation on the stage.void
Starts the beating animation for the health bar during boss chase.void
void
void
updatePlayerExperienceUI
(int experience, CombatStatsComponent combatStats) Updates the experience animation and label in game to reflect current player experience including the call to test functions for checkingvoid
updatePlayerHealthUI
(int health, int maxHealth, boolean isPlayer) Updates the health animation and label in game to reflect current player health including the call to test functions for checkingvoid
updatePlayerHungerUI
(int hunger) Updates the hunger animation and label in game to reflect current player hunger including the call to test functions for checkingMethods inherited from class com.csse3200.game.ui.UIComponent
getLayer, getZIndex, setStage
Methods inherited from class com.csse3200.game.rendering.RenderComponent
compareTo, render
Methods inherited from class com.csse3200.game.components.Component
earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Comparable
compareTo
Methods inherited from interface com.csse3200.game.rendering.Renderable
render
-
Field Details
-
healthImage
public com.badlogic.gdx.scenes.scene2d.ui.Image healthImage -
xpImage
public com.badlogic.gdx.scenes.scene2d.ui.Image xpImage -
hungerImage
public com.badlogic.gdx.scenes.scene2d.ui.Image hungerImage -
healthLabel
public com.badlogic.gdx.scenes.scene2d.ui.Label healthLabel -
hungerLabel
public com.badlogic.gdx.scenes.scene2d.ui.Label hungerLabel -
textureAtlas
public com.badlogic.gdx.graphics.g2d.TextureAtlas[] textureAtlas -
totalFrames
public int totalFrames -
addActorsTester
public boolean addActorsTester -
maxHealth
public int maxHealth -
maxHunger
public int maxHunger -
maxExperience
public int maxExperience
-
-
Constructor Details
-
PlayerStatsDisplay
public PlayerStatsDisplay()
-
-
Method Details
-
create
public void create()Initializes and adds actors (UI elements) to the stage. Registers listeners for updating health, experience, and hunger. Makes call to the test method testCreate- Overrides:
create
in classUIComponent
-
initBarAnimations
public void initBarAnimations()Initializes the animations for the health, hunger, and experience bars. Each bar's animation consist of series of consecutive frames from a texture atlas given in the assets folder. The animations reflect the current status of the player's health, hunger, and experience. -
startHungerDecreaseTimer
public void startHungerDecreaseTimer() -
draw
public void draw(com.badlogic.gdx.graphics.g2d.SpriteBatch batch) Description copied from class:RenderComponent
Draw the renderable. Should be called only by the renderer, not manually.- Specified by:
draw
in classRenderComponent
- Parameters:
batch
- Batch to render to.
-
setNewFrame
public void setNewFrame(int frameIndex, com.badlogic.gdx.graphics.g2d.Animation<com.badlogic.gdx.graphics.g2d.TextureRegion> statBarAnimation, com.badlogic.gdx.scenes.scene2d.ui.Image statBar) Sets a new frame for a stat bar animation on the stage.- Parameters:
frameIndex
- The index of the desired frame in the animation to be changedstatBarAnimation
- The animation for the specific stat bar to be changedstatBar
- image that stores the current frame on the stage for the stat bar.
-
updatePlayerHealthUI
public void updatePlayerHealthUI(int health, int maxHealth, boolean isPlayer) Updates the health animation and label in game to reflect current player health including the call to test functions for checking- Parameters:
health
- the current health stat value of the player
-
updatePlayerHungerUI
public void updatePlayerHungerUI(int hunger) Updates the hunger animation and label in game to reflect current player hunger including the call to test functions for checking- Parameters:
hunger
- The current hunger stat value of the player
-
updatePlayerExperienceUI
Updates the experience animation and label in game to reflect current player experience including the call to test functions for checking- Parameters:
experience
- The current experience stat value of the player
-
startHealthBarBeating
public void startHealthBarBeating()Starts the beating animation for the health bar during boss chase. -
stopHealthBarBeating
public void stopHealthBarBeating() -
dispose
public void dispose()Disposes of the resources used by the PlayerStatsDisplay component, including textures and labels.- Specified by:
dispose
in interfacecom.badlogic.gdx.utils.Disposable
- Overrides:
dispose
in classRenderComponent
-