Add knockback when attacking, fix animation state
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user