From: Elias Fleckenstein Date: Wed, 9 Jun 2021 15:32:40 +0000 (+0200) Subject: Only call on_death callback if entity was alive before X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=70374f3ca40208261ae728c12cdf91e8506ff578;p=dungeon_game.git Only call on_death callback if entity was alive before --- diff --git a/plugins/game/game.c b/plugins/game/game.c index b283214..74892c8 100644 --- a/plugins/game/game.c +++ b/plugins/game/game.c @@ -111,11 +111,13 @@ void spawn(struct entity def, int x, int y) void add_health(struct entity *entity, int health) { + bool was_alive = entity->health > 0; + entity->health += health; if (entity->health > entity->max_health) entity->health = entity->max_health; - else if (entity->health <= 0 && entity->on_death) + else if (entity->health <= 0 && was_alive && entity->on_death) entity->on_death(entity); }