21 for (
const auto &[entity, player] : playerEntities)
27 if (transform && health)
30 if (health->current < health->max)
32 drawHealthBar(transform->x, transform->y, health->current, health->max);
40 if (healthPercent > 0.75f)
44 else if (healthPercent > 0.50f)
48 else if (healthPercent > 0.25f)
60 if (maxHealth <= 0.0f)
64 float healthPercent = std::clamp(currentHealth / maxHealth, 0.0f, 1.0f);
73 std::string healthCircleName =
74 "health_" + std::to_string(
static_cast<int>(x)) +
"_" + std::to_string(
static_cast<int>(y));
77 float circleRadius = 3.0f;
80 .radius = circleRadius,
This file contains the component definitions.
System for rendering health bars above entities in multiplayer mode.
This file contains the Logger class.
Class for managing entities and their components.
std::unordered_map< Entity, T > & getAll()
T * getComponent(Entity e)
virtual void createCircleShape(CircleShape circleShape)=0
virtual void drawCircleShape(const std::string &name)=0
static constexpr float BAR_WIDTH
Width of the health bar in pixels.
static constexpr eng::Color HEALTH_HIGH
Green color for >75% health.
void update(ecs::Registry ®istry, float dt) override
Update the health bar system (called each frame)
void drawHealthBar(float x, float y, float currentHealth, float maxHealth)
Render a health bar at specified position.
static constexpr eng::Color HEALTH_CRITICAL
Red color for <25% health.
eng::Color getHealthColor(float healthPercent) const
Calculate health bar color based on health percentage.
static constexpr float BAR_OFFSET_Y
Vertical offset above entity (negative = above)
static constexpr eng::Color HEALTH_MEDIUM
Yellow color for 50-75% health.
static constexpr eng::Color HEALTH_LOW
Orange color for 25-50% health.
HealthBarSystem(const std::shared_ptr< eng::IRenderer > &renderer)
Constructor.
const std::shared_ptr< eng::IRenderer > & m_renderer
Reference to the renderer for drawing.