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) | |
| HealthBarSystem & | operator= (const HealthBarSystem &)=delete |
| Deleted copy assignment operator (non-copyable) | |
| HealthBarSystem (HealthBarSystem &&)=delete | |
| Deleted move constructor (non-movable) | |
| HealthBarSystem & | operator= (HealthBarSystem &&)=delete |
| Deleted move assignment operator (non-movable) | |
| void | update (ecs::Registry ®istry, 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. | |
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:
The system is designed for multiplayer where multiple players and enemies need health indicators.
Definition at line 35 of file HealthBarSystem.hpp.
|
explicit |
Constructor.
| renderer | Shared pointer to the rendering interface |
Definition at line 14 of file HealthBarSystem.cpp.
|
overridedefault |
Destructor.
|
delete |
Deleted copy constructor (non-copyable)
|
delete |
Deleted move constructor (non-movable)
|
private |
Render a health bar at specified position.
| x | X position (center of entity) |
| y | Y position (center of entity) |
| currentHealth | Current health value |
| maxHealth | Maximum health value |
Draws a layered health bar with:
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:
|
private |
Calculate health bar color based on health percentage.
| healthPercent | Health percentage (0.0 = dead, 1.0 = full health) |
Color transitions:
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:
|
delete |
Deleted copy assignment operator (non-copyable)
|
delete |
Deleted move assignment operator (non-movable)
|
overridevirtual |
Update the health bar system (called each frame)
| registry | ECS registry containing all entities |
| dt | Delta 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:
|
staticconstexprprivate |
Dark gray background (semi-transparent)
Definition at line 92 of file HealthBarSystem.hpp.
|
staticconstexprprivate |
Height of the health bar in pixels.
Definition at line 83 of file HealthBarSystem.hpp.
|
staticconstexprprivate |
Vertical offset above entity (negative = above)
Definition at line 84 of file HealthBarSystem.hpp.
Referenced by drawHealthBar().
|
staticconstexprprivate |
Width of the health bar in pixels.
Definition at line 82 of file HealthBarSystem.hpp.
Referenced by drawHealthBar().
|
staticconstexprprivate |
White border color.
Definition at line 93 of file HealthBarSystem.hpp.
|
staticconstexprprivate |
Thickness of the border around the bar.
Definition at line 85 of file HealthBarSystem.hpp.
|
staticconstexprprivate |
Red color for <25% health.
Definition at line 91 of file HealthBarSystem.hpp.
Referenced by getHealthColor().
|
staticconstexprprivate |
Green color for >75% health.
Definition at line 88 of file HealthBarSystem.hpp.
Referenced by getHealthColor().
|
staticconstexprprivate |
Orange color for 25-50% health.
Definition at line 90 of file HealthBarSystem.hpp.
Referenced by getHealthColor().
|
staticconstexprprivate |
Yellow color for 50-75% health.
Definition at line 89 of file HealthBarSystem.hpp.
Referenced by getHealthColor().
|
private |
Reference to the renderer for drawing.
Definition at line 79 of file HealthBarSystem.hpp.
Referenced by drawHealthBar().