r-type  0.0.0
R-Type main
Loading...
Searching...
No Matches
gme::HealthBarSystem Class Referencefinal

ECS System that renders dynamic health bars above entities. More...

#include <HealthBarSystem.hpp>

+ Inheritance diagram for gme::HealthBarSystem:
+ Collaboration diagram for gme::HealthBarSystem:

Public Member Functions

 HealthBarSystem (const std::shared_ptr< eng::IRenderer > &renderer)
 Constructor.
 
 ~HealthBarSystem () override=default
 Destructor.
 
 HealthBarSystem (const HealthBarSystem &)=delete
 Deleted copy constructor (non-copyable)
 
HealthBarSystemoperator= (const HealthBarSystem &)=delete
 Deleted copy assignment operator (non-copyable)
 
 HealthBarSystem (HealthBarSystem &&)=delete
 Deleted move constructor (non-movable)
 
HealthBarSystemoperator= (HealthBarSystem &&)=delete
 Deleted move assignment operator (non-movable)
 
void update (ecs::Registry &registry, float dt) override
 Update the health bar system (called each frame)
 
- Public Member Functions inherited from ecs::ASystem
bool isEnable () override
 
void setEnable (const bool enable) override
 
- Public Member Functions inherited from ecs::ISystem
virtual ~ISystem ()=default
 

Private Member Functions

eng::Color getHealthColor (float healthPercent) const
 Calculate health bar color based on health percentage.
 
void drawHealthBar (float x, float y, float currentHealth, float maxHealth)
 Render a health bar at specified position.
 

Private Attributes

const std::shared_ptr< eng::IRenderer > & m_renderer
 Reference to the renderer for drawing.
 

Static Private Attributes

static constexpr float BAR_WIDTH = 40.0f
 Width of the health bar in pixels.
 
static constexpr float BAR_HEIGHT = 4.0f
 Height of the health bar in pixels.
 
static constexpr float BAR_OFFSET_Y = -15.0f
 Vertical offset above entity (negative = above)
 
static constexpr float BORDER_THICKNESS = 1.0f
 Thickness of the border around the bar.
 
static constexpr eng::Color HEALTH_HIGH = {0, 255, 0, 255}
 Green color for >75% health.
 
static constexpr eng::Color HEALTH_MEDIUM = {255, 255, 0, 255}
 Yellow color for 50-75% health.
 
static constexpr eng::Color HEALTH_LOW = {255, 100, 0, 255}
 Orange color for 25-50% health.
 
static constexpr eng::Color HEALTH_CRITICAL = {255, 0, 0, 255}
 Red color for <25% health.
 
static constexpr eng::Color BACKGROUND = {50, 50, 50, 200}
 Dark gray background (semi-transparent)
 
static constexpr eng::Color BORDER = {255, 255, 255, 255}
 White border color.
 

Detailed Description

ECS System that renders dynamic health bars above entities.

This system queries all entities with a Health component and renders a visual health bar above each entity. Features include:

  • Dynamic color based on health percentage (green -> yellow -> orange -> red)
  • Positioned above entities with configurable offset
  • Border and background for better visibility
  • Automatic health percentage calculation

The system is designed for multiplayer where multiple players and enemies need health indicators.

Definition at line 35 of file HealthBarSystem.hpp.

Constructor & Destructor Documentation

◆ HealthBarSystem() [1/3]

gme::HealthBarSystem::HealthBarSystem ( const std::shared_ptr< eng::IRenderer > & renderer)
explicit

Constructor.

Parameters
rendererShared pointer to the rendering interface

Definition at line 14 of file HealthBarSystem.cpp.

◆ ~HealthBarSystem()

gme::HealthBarSystem::~HealthBarSystem ( )
overridedefault

Destructor.

◆ HealthBarSystem() [2/3]

gme::HealthBarSystem::HealthBarSystem ( const HealthBarSystem & )
delete

Deleted copy constructor (non-copyable)

◆ HealthBarSystem() [3/3]

gme::HealthBarSystem::HealthBarSystem ( HealthBarSystem && )
delete

Deleted move constructor (non-movable)

Member Function Documentation

◆ drawHealthBar()

void gme::HealthBarSystem::drawHealthBar ( float x,
float y,
float currentHealth,
float maxHealth )
private

Render a health bar at specified position.

Parameters
xX position (center of entity)
yY position (center of entity)
currentHealthCurrent health value
maxHealthMaximum health value

Draws a layered health bar with:

  1. White border
  2. Dark gray background
  3. Colored health fill (proportional to current/max health)

Definition at line 58 of file HealthBarSystem.cpp.

References BAR_OFFSET_Y, BAR_WIDTH, eng::IRenderer::createCircleShape(), eng::IRenderer::drawCircleShape(), getHealthColor(), and m_renderer.

Referenced by update().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHealthColor()

eng::Color gme::HealthBarSystem::getHealthColor ( float healthPercent) const
private

Calculate health bar color based on health percentage.

Parameters
healthPercentHealth percentage (0.0 = dead, 1.0 = full health)
Returns
Color for the health bar fill

Color transitions:

  • >75%: Green (HEALTH_HIGH)
  • 50-75%: Yellow (HEALTH_MEDIUM)
  • 25-50%: Orange (HEALTH_LOW)
  • <25%: Red (HEALTH_CRITICAL)

Definition at line 38 of file HealthBarSystem.cpp.

References HEALTH_CRITICAL, HEALTH_HIGH, HEALTH_LOW, and HEALTH_MEDIUM.

Referenced by drawHealthBar().

+ Here is the caller graph for this function:

◆ operator=() [1/2]

HealthBarSystem & gme::HealthBarSystem::operator= ( const HealthBarSystem & )
delete

Deleted copy assignment operator (non-copyable)

◆ operator=() [2/2]

HealthBarSystem & gme::HealthBarSystem::operator= ( HealthBarSystem && )
delete

Deleted move assignment operator (non-movable)

◆ update()

void gme::HealthBarSystem::update ( ecs::Registry & registry,
float dt )
overridevirtual

Update the health bar system (called each frame)

Parameters
registryECS registry containing all entities
dtDelta time since last frame (unused)

Iterates through all entities with Health and Transform components and renders a health bar above each one

Implements ecs::ISystem.

Definition at line 16 of file HealthBarSystem.cpp.

References drawHealthBar(), ecs::Registry::getAll(), and ecs::Registry::getComponent().

+ Here is the call graph for this function:

Member Data Documentation

◆ BACKGROUND

eng::Color gme::HealthBarSystem::BACKGROUND = {50, 50, 50, 200}
staticconstexprprivate

Dark gray background (semi-transparent)

Definition at line 92 of file HealthBarSystem.hpp.

◆ BAR_HEIGHT

float gme::HealthBarSystem::BAR_HEIGHT = 4.0f
staticconstexprprivate

Height of the health bar in pixels.

Definition at line 83 of file HealthBarSystem.hpp.

◆ BAR_OFFSET_Y

float gme::HealthBarSystem::BAR_OFFSET_Y = -15.0f
staticconstexprprivate

Vertical offset above entity (negative = above)

Definition at line 84 of file HealthBarSystem.hpp.

Referenced by drawHealthBar().

◆ BAR_WIDTH

float gme::HealthBarSystem::BAR_WIDTH = 40.0f
staticconstexprprivate

Width of the health bar in pixels.

Definition at line 82 of file HealthBarSystem.hpp.

Referenced by drawHealthBar().

◆ BORDER

eng::Color gme::HealthBarSystem::BORDER = {255, 255, 255, 255}
staticconstexprprivate

White border color.

Definition at line 93 of file HealthBarSystem.hpp.

◆ BORDER_THICKNESS

float gme::HealthBarSystem::BORDER_THICKNESS = 1.0f
staticconstexprprivate

Thickness of the border around the bar.

Definition at line 85 of file HealthBarSystem.hpp.

◆ HEALTH_CRITICAL

eng::Color gme::HealthBarSystem::HEALTH_CRITICAL = {255, 0, 0, 255}
staticconstexprprivate

Red color for <25% health.

Definition at line 91 of file HealthBarSystem.hpp.

Referenced by getHealthColor().

◆ HEALTH_HIGH

eng::Color gme::HealthBarSystem::HEALTH_HIGH = {0, 255, 0, 255}
staticconstexprprivate

Green color for >75% health.

Definition at line 88 of file HealthBarSystem.hpp.

Referenced by getHealthColor().

◆ HEALTH_LOW

eng::Color gme::HealthBarSystem::HEALTH_LOW = {255, 100, 0, 255}
staticconstexprprivate

Orange color for 25-50% health.

Definition at line 90 of file HealthBarSystem.hpp.

Referenced by getHealthColor().

◆ HEALTH_MEDIUM

eng::Color gme::HealthBarSystem::HEALTH_MEDIUM = {255, 255, 0, 255}
staticconstexprprivate

Yellow color for 50-75% health.

Definition at line 89 of file HealthBarSystem.hpp.

Referenced by getHealthColor().

◆ m_renderer

const std::shared_ptr<eng::IRenderer>& gme::HealthBarSystem::m_renderer
private

Reference to the renderer for drawing.

Definition at line 79 of file HealthBarSystem.hpp.

Referenced by drawHealthBar().


The documentation for this class was generated from the following files: