Combat HUD cleanup and low health warning - UQcsse3200/2026-studio-4 GitHub Wiki

Combat HUD cleanup and low-health warning

Task: #145
Feature: HUD #98

Top-left combat HUD shows only Health: current / max and the health bar. Debug stats (movement speed, attack speed, strength) are hidden from that corner. At or below 25% of max HP the bar and label turn red.

Participants

  • CombatStatsComponent (updateHealth, updateMaxHealth)
  • PlayerStatsDisplay

Behaviour

  • Combat corner: health label + bar only.
  • Low health: health <= 0.25 * max → red + pulse.
  • Heal or max-HP change: warning clears if health is above 25% again.
  • Room change: still one HUD on the player entity.

Class diagram

classDiagram
    class UIComponent {
        <<abstract>>
    }
    class CombatStatsComponent {
        -int health
        -int maxHealth
        +getHealth() int
        +getMaxHealth() int
        +setHealth(int)
        +setMaxHealth(int)
        +takeDamage(...)
    }
    class PlayerStatsDisplay {
        -Label healthValueLabel
        -ProgressBar healthBar
        -int health
        -int maxHealth
        -boolean lowHealthWarning
        +create()
        +updatePlayerHealthUI(int)
        +updatePlayerMaxHealthUI(int)
        +isLowHealthWarning() boolean
        -refreshLowHealthWarning()
        -healthText() String
    }
    class Entity {
        +getEvents()
    }

    UIComponent <|-- PlayerStatsDisplay
    UIComponent <|-- CombatStatsComponent
    Entity o-- PlayerStatsDisplay
    Entity o-- CombatStatsComponent
    CombatStatsComponent --> PlayerStatsDisplay : updateHealth / updateMaxHealth
Loading

Sequence diagram

sequenceDiagram
    participant Stats as CombatStatsComponent
    participant Events as Entity events
    participant HUD as PlayerStatsDisplay

    Stats->>Events: updateHealth(hp)
    Events->>HUD: updatePlayerHealthUI(hp)
    HUD->>HUD: set Health: hp / max
    HUD->>HUD: set bar value
    HUD->>HUD: refreshLowHealthWarning()

    alt hp <= 25% of max
        HUD->>HUD: red bar and label
    else hp above 25%
        HUD->>HUD: normal colour
    end

    Stats->>Events: updateMaxHealth(max)
    Events->>HUD: updatePlayerMaxHealthUI(max)
    HUD->>HUD: bar range + threshold again
Loading

Flowchart

flowchart TD
    A[updateHealth or updateMaxHealth] --> B[Set label Health: current / max]
    B --> C[Update health bar]
    C --> D{health <= 25% of max?}
    D -->|yes| E[Red bar and label, pulse]
    D -->|no| F[Normal colour, no warning]
Loading

Tests

  • PlayerStatsDisplayTest — hidden debug labels, 25% threshold, colour, recover
⚠️ **GitHub.com Fallback** ⚠️