From 87c5703c60b65f331c261e7dcb2b6f2a1112c78b Mon Sep 17 00:00:00 2001 From: Zoe Roux Date: Mon, 31 May 2021 20:14:07 +0200 Subject: [PATCH] Adding a on death callback --- sources/Component/Health/HealthComponent.hpp | 4 ++++ sources/Runner/Runner.cpp | 2 +- sources/System/Health/HealthSystem.cpp | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sources/Component/Health/HealthComponent.hpp b/sources/Component/Health/HealthComponent.hpp index a7c72c7f..2eadafc5 100644 --- a/sources/Component/Health/HealthComponent.hpp +++ b/sources/Component/Health/HealthComponent.hpp @@ -6,6 +6,7 @@ #pragma once +#include #include "Component/Component.hpp" #include "Entity/Entity.hpp" @@ -19,6 +20,9 @@ namespace BBM unsigned int _healthPoint; public: + //! @brief The callback invoked on this entity's death. + WAL::Callback onDeath; + //! @brief add health to the entity void addHealthPoint(unsigned int healthPoint); diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index c6a6c196..9e527fcb 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -41,7 +41,7 @@ namespace BBM void addSystems(WAL::Wal &wal) { wal.addSystem() - .addSystem() + .addSystem() .addSystem() .addSystem(); } diff --git a/sources/System/Health/HealthSystem.cpp b/sources/System/Health/HealthSystem.cpp index a3ecee88..90bbfbb9 100644 --- a/sources/System/Health/HealthSystem.cpp +++ b/sources/System/Health/HealthSystem.cpp @@ -20,7 +20,7 @@ namespace BBM { auto &health = entity.getComponent(); - if (health.getHealthPoint() == 0); - entity.setDisable(true); + if (health.getHealthPoint() == 0) + health.onDeath(entity); } } \ No newline at end of file