Health Deduction System
Source file: client/engine/systems/systems_functions/HealthDeductionSystem.cpp
Purpose: Handle projectile/target collisions, apply damage, trigger hit/death animations, and clean up destroyed entities.
Components used:
Health(current hit points)HealthBar(damage timer refresh)AnimatedSprite("Hit" and "Death" animations)HitBox(AABB collision)Transform(positions for AABB test)Projectile(damage, ownership)PlayerTag/EnemyTag(friend/foe filtering)TimedEvents,FrameEvents,PatternMovement(removed on death)
Behavior
- For each entity with
Health, iterates projectiles and tests collision viaIsColliding(AABB). - Skips friendly fire based on
projectile.isEnemyProjectileagainst Player/Enemy tags. - On impact:
- Decrements
health.currentHealthbyprojectile.damage. - Resets
health_bar.timer_damageto 0 if present. - Plays "Hit" animation and forces frame 1 if
AnimatedSpriteexists. - Removes
Projectilefrom the projectile entity; if it has a sprite, plays "Death" and addsAnimationDeath, otherwise kills it.
- Decrements
- If
health.currentHealth <= 0, invokesDeathHandling: addsAnimationDeath, removesHealth,HitBox, Player/Enemy tags,TimedEvents,FrameEvents,PatternMovement, then plays "Death" if available or kills the entity.
Main signature
void HealthDeductionSystem(Eng::registry ®,
Eng::sparse_array<Component::Health> &healths,
Eng::sparse_array<Component::HealthBar> &health_bars,
Eng::sparse_array<Component::AnimatedSprite> &animated_sprites,
Eng::sparse_array<Component::HitBox> const &hitBoxes,
Eng::sparse_array<Component::Transform> const &transforms,
Eng::sparse_array<Component::Projectile> const &projectiles);
Notes
- AABB checks include offsets/scales via
IsColliding(seeCollidingTools). - "Hit"/"Death" handling assumes non-looping projectile animations.
- Entities with no collision or remaining health are unaffected.