Class PlayerStatsDisplay

All Implemented Interfaces:
com.badlogic.gdx.utils.Disposable, Renderable, Comparable<Renderable>

public class PlayerStatsDisplay extends UIComponent
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 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 class UIComponent
    • 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 class RenderComponent
      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 changed
      statBarAnimation - The animation for the specific stat bar to be changed
      statBar - 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

      public 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 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 interface com.badlogic.gdx.utils.Disposable
      Overrides:
      dispose in class RenderComponent