Add hurt, die animation when taking damage

This commit is contained in:
2024-02-07 17:14:17 +01:00
parent d6466b8f55
commit 6c1d0dfdb2
16 changed files with 251 additions and 24 deletions

View File

@@ -73,6 +73,19 @@ ECS_MOVE(Building, dst, src, {
*dst = *src;
})
void delayDeleteUpdate(ecs_iter_t *it) {
DelayDelete *delay = ecs_field(it, DelayDelete, 1);
f32 dt = GetFrameTime();
for (i32 i = 0; i < it->count; i++) {
delay[i].elapsed += dt;
if (delay[i].elapsed >= delay[i].time)
ecs_delete(ECS, it->entities[i]);
}
}
void setupSystems() {
ecs_set_hooks(ECS, SpatialGridID, {
.dtor = ecs_dtor(SpatialGridID),
@@ -99,7 +112,7 @@ void setupSystems() {
ECS_SYSTEM(ECS, entityUpdateSpatialID, EcsOnUpdate, Position, HitBox, Velocity, SpatialGridID);
ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Velocity, Steering, Unit);
ECS_SYSTEM(ECS, entityUpdatePhysics, EcsOnUpdate, Position, HitBox, Velocity, SpatialGridID);
ECS_SYSTEM(ECS, entityUpdate, EcsOnUpdate, Position, HitBox, Velocity, Unit, Owner, SpatialGridID);
ECS_SYSTEM(ECS, entityMoveToTarget, EcsOnUpdate, Position, Velocity, TargetPosition, Steering);
ECS_SYSTEM(ECS, entityFollowPath, EcsOnUpdate, Path);
@@ -113,12 +126,14 @@ void setupSystems() {
ECS_SYSTEM(ECS, updateAnimation, EcsOnUpdate, Animation, TextureRegion);
ECS_SYSTEM(ECS, updateEasingSystem, EcsOnUpdate, Easing, Position, HitBox, Rotation);
ECS_SYSTEM(ECS, renderHealth, EcsOnUpdate, Position, HitBox, Health);
ECS_SYSTEM(ECS, renderHealthBar, EcsOnUpdate, Position, HitBox, Health);
ECS_SYSTEM(ECS, renderDebugPath, EcsOnUpdate, Path);
ECS_SYSTEM(ECS, renderColliders, EcsOnUpdate, Position, HitBox);
ECS_SYSTEM(ECS, renderOrientationDirection, EcsOnUpdate, Position, Orientation);
ECS_SYSTEM(ECS, delayDeleteUpdate, EcsOnUpdate, DelayDelete);
renderDebugPathSystem = renderDebugPath;
renderOrientDirSystem = renderOrientationDirection;
renderCollidersSystem = renderColliders;