R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
ecs::Health Class Reference

Component representing entity health and invincibility. More...

#include <Health.hpp>

Inheritance diagram for ecs::Health:
Inheritance graph
Collaboration diagram for ecs::Health:
Collaboration graph

Public Member Functions

 Health (int maxHealth)
 Constructor with maximum health only. Sets current health equal to max health.
 
 Health (int currentHealth, int maxHealth)
 Constructor with current and maximum health.
 
 ~Health () override=default
 
int getCurrentHealth () const
 Get current health points.
 
int getMaxHealth () const
 Get maximum health points.
 
bool isInvincible () const
 Check if entity is invincible.
 
float getInvincibilityTimer () const
 Get remaining invincibility time.
 
void setMaxHealth (int health)
 Set maximum health.
 
void setCurrentHealth (int health)
 Set current health.
 
void setInvincible (bool invincible)
 Set invincibility state.
 
void setInvincibilityTimer (float timer)
 Set invincibility timer.
 
bool takeDamage (int amount)
 Apply damage to the entity. Respects invincibility frames - no damage taken if invincible.
 
void heal (int amount)
 Restore health points. Cannot exceed maximum health.
 
bool isDead () const
 Check if entity is dead (health <= 0).
 
ComponentType getType () const override
 Get the component type ID.
 
- Public Member Functions inherited from ecs::IComponent
virtual ~IComponent ()=default
 Virtual destructor.
 

Private Attributes

int _current
 Current health points.
 
int _max
 Maximum health points.
 
bool _invincible
 Invincibility state.
 
float _timer
 Invincibility duration timer in seconds.
 

Detailed Description

Component representing entity health and invincibility.

Stores current and maximum health values, as well as temporary invincibility state. The invincibility timer is decremented by systems to manage temporary immunity.

Definition at line 20 of file Health.hpp.

Constructor & Destructor Documentation

◆ Health() [1/2]

ecs::Health::Health ( int  maxHealth)
inlineexplicit

Constructor with maximum health only. Sets current health equal to max health.

Parameters
maxHealthMaximum health points

Definition at line 27 of file Health.hpp.

◆ Health() [2/2]

ecs::Health::Health ( int  currentHealth,
int  maxHealth 
)
inline

Constructor with current and maximum health.

Parameters
currentHealthStarting health points
maxHealthMaximum health points

Definition at line 35 of file Health.hpp.

◆ ~Health()

ecs::Health::~Health ( )
overridedefault

Member Function Documentation

◆ getCurrentHealth()

◆ getInvincibilityTimer()

float ecs::Health::getInvincibilityTimer ( ) const
inline

Get remaining invincibility time.

Returns
float Timer value in seconds.

Definition at line 62 of file Health.hpp.

References _timer.

Referenced by scripting::bindings::bindComponents(), and ecs::HealthSystem::update().

◆ getMaxHealth()

int ecs::Health::getMaxHealth ( ) const
inline

◆ getType()

ComponentType ecs::Health::getType ( ) const
inlineoverridevirtual

Get the component type ID.

Returns
ComponentType Unique ID for Health component.

Implements ecs::IComponent.

Definition at line 130 of file Health.hpp.

◆ heal()

void ecs::Health::heal ( int  amount)
inline

Restore health points. Cannot exceed maximum health.

Parameters
amountHealth to restore (positive value)

Definition at line 110 of file Health.hpp.

References _current, and _max.

◆ isDead()

bool ecs::Health::isDead ( ) const
inline

Check if entity is dead (health <= 0).

Returns
bool True if dead, false if alive.

Definition at line 124 of file Health.hpp.

References _current.

◆ isInvincible()

bool ecs::Health::isInvincible ( ) const
inline

Check if entity is invincible.

Returns
bool True if invincible, false otherwise.

Definition at line 56 of file Health.hpp.

References _invincible.

Referenced by scripting::bindings::bindComponents().

◆ setCurrentHealth()

void ecs::Health::setCurrentHealth ( int  health)
inline

◆ setInvincibilityTimer()

void ecs::Health::setInvincibilityTimer ( float  timer)
inline

Set invincibility timer.

Parameters
timerTimer value in seconds

Definition at line 86 of file Health.hpp.

References _timer.

Referenced by ecs::BuffSystem::_applyShield(), and scripting::bindings::bindComponents().

◆ setInvincible()

void ecs::Health::setInvincible ( bool  invincible)
inline

Set invincibility state.

Parameters
invincibleTrue to enable invincibility

Definition at line 80 of file Health.hpp.

References _invincible.

Referenced by ecs::BuffSystem::_applyShield(), and scripting::bindings::bindComponents().

◆ setMaxHealth()

void ecs::Health::setMaxHealth ( int  health)
inline

Set maximum health.

Parameters
healthNew maximum health value

Definition at line 68 of file Health.hpp.

References _max.

Referenced by scripting::bindings::bindComponents(), and ecs::CollisionSystem::handlePickup().

◆ takeDamage()

bool ecs::Health::takeDamage ( int  amount)
inline

Apply damage to the entity. Respects invincibility frames - no damage taken if invincible.

Parameters
amountDamage amount (positive value)
Returns
bool True if damage was applied, false if blocked by invincibility

Definition at line 94 of file Health.hpp.

References _current, and _invincible.

Referenced by ecs::CollisionSystem::handleProjectileCollision().

Member Data Documentation

◆ _current

int ecs::Health::_current
private

Current health points.

Definition at line 133 of file Health.hpp.

Referenced by getCurrentHealth(), heal(), isDead(), setCurrentHealth(), and takeDamage().

◆ _invincible

bool ecs::Health::_invincible
private

Invincibility state.

Definition at line 135 of file Health.hpp.

Referenced by isInvincible(), setInvincible(), and takeDamage().

◆ _max

int ecs::Health::_max
private

Maximum health points.

Definition at line 134 of file Health.hpp.

Referenced by getMaxHealth(), heal(), and setMaxHealth().

◆ _timer

float ecs::Health::_timer
private

Invincibility duration timer in seconds.

Definition at line 136 of file Health.hpp.

Referenced by getInvincibilityTimer(), and setInvincibilityTimer().


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