Add knockback when attacking, fix animation state

This commit is contained in:
2024-02-09 18:50:18 +01:00
parent 484e5e9b39
commit b8da0a9f2d
4 changed files with 28 additions and 17 deletions

View File

@@ -33,14 +33,16 @@ void damageEvent(ecs_entity_t entity, DamageEvent event) {
bool hasAnimation = ecs_has(ECS, entity, Animation);
if (hasAnimation && health->hp > 0) {
// Still alive, just play hurt anim
Animation *animation = ecs_get_mut(ECS, entity, Animation);
animationSetState(animation, ANIM_HURT, true);
Animation *anim = ecs_get_mut(ECS, entity, Animation);
TextureRegion *tex = ecs_get_mut(ECS, entity, TextureRegion);
animationSetState(entity, anim, tex, ANIM_HURT, true);
} else if (hasAnimation) {
// Delay delete
Animation *animation = ecs_get_mut(ECS, entity, Animation);
animationSetState(animation, ANIM_DIE, true);
Animation *anim = ecs_get_mut(ECS, entity, Animation);
TextureRegion *tex = ecs_get_mut(ECS, entity, TextureRegion);
animationSetState(entity, anim, tex, ANIM_DIE, true);
ecs_set(ECS, entity, DelayDelete, {
.time = entityGetAnimationLength(animation->entityType, ANIM_DIE)
.time = entityGetAnimationLength(anim->entityType, ANIM_DIE)
});
// Remove, so it becomes inactive
ecs_remove_id(ECS, entity, Selectable);