LivesComponent
Location: shared/include/components/LivesComponent.hpp
Represents the player's remaining lives/continues and maximum capacity. Provides helpers to add/remove lives with clamping.
Structure
struct LivesComponent
{
int current = 0;
int max = 0;
static LivesComponent create(int currentLives, int maxLives);
void loseLife(int amount = 1);
void addLife(int amount = 1);
void addExtraLife(int amount = 1);
void setMax(int newMax);
void resetToMax();
bool isDead() const;
};
Behavior
loseLifedecrements and clamps to zero; ignores non-positive values.addLifeincrements up tomax; ignores non-positive values.addExtraLifeincreases bothmaxandcurrentby the same positive amount.setMaxclamps negative max to zero and trimscurrentif above the new max.resetToMaxsetscurrent = max.isDeadis true whencurrent <= 0.
Usage
auto lives = LivesComponent::create(3, 3);
registry.emplace<LivesComponent>(playerId, lives);
// Lose one life on death
auto& lc = registry.get<LivesComponent>(playerId);
lc.loseLife();
// Extra life pickup
lc.addExtraLife(); // max and current +1
// Refill on respawn
lc.resetToMax();
Notes
- Component is shared-side; replicated state can drive client HUD ("Lives: current/max").
- Distinct from
HealthComponent(HP). Lives typically count respawns/continues, not hit points.