From 1261476a0043431fca4deea02420d97684ecf6dc Mon Sep 17 00:00:00 2001 From: Askou Date: Thu, 17 Jun 2021 09:52:45 +0200 Subject: [PATCH] try to add death timer --- lib/wal/sources/Entity/Entity.hpp | 2 +- sources/Runner/GameScene.cpp | 3 +++ sources/System/Animator/AnimatorSystem.cpp | 5 +++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/wal/sources/Entity/Entity.hpp b/lib/wal/sources/Entity/Entity.hpp index 5cffcc5f..0cad61b9 100644 --- a/lib/wal/sources/Entity/Entity.hpp +++ b/lib/wal/sources/Entity/Entity.hpp @@ -144,7 +144,7 @@ namespace WAL { const std::type_index &type = typeid(T); if (this->hasComponent(type)) - throw DuplicateError("A component of the type \"" + std::string(type.name()) + "\" already exists."); + throw DuplicateError("A component of the type \"" + std::string(type.name()) + "\" already exists on " + this->_name + "."); this->_components[type] = std::make_unique(*this, TypeHolder()..., std::forward(params)...); if (this->_notifyScene) this->_componentAdded(type); diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index b2e6f279..f8b13f5a 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -82,6 +82,9 @@ namespace BBM .addComponent(1, [](WAL::Entity &entity, WAL::Wal &) { auto &animation = entity.getComponent(); animation.setAnimIndex(5); + entity.addComponent(5s, [](WAL::Entity &entity, WAL::Wal &wal) { + entity.scheduleDeletion(); + }); }); } } \ No newline at end of file diff --git a/sources/System/Animator/AnimatorSystem.cpp b/sources/System/Animator/AnimatorSystem.cpp index f03aeb9b..e4df9dbc 100644 --- a/sources/System/Animator/AnimatorSystem.cpp +++ b/sources/System/Animator/AnimatorSystem.cpp @@ -10,6 +10,7 @@ #include #include "AnimatorSystem.hpp" #include "Component/Renderer/Drawable3DComponent.hpp" +#include "Component/Health/HealthComponent.hpp" using Keyboard = RAY::Controller::Keyboard; namespace RAY3D = RAY::Drawables::Drawables3D; @@ -27,6 +28,10 @@ namespace BBM auto drawable = entity.get().drawable.get(); auto &animation = entity.get(); auto anim = dynamic_cast(drawable); + auto health = entity->tryGetComponent(); + + if (health && health->getHealthPoint() <= 0) + return; if (anim && controllable.move != Vector2f(0, 0)) { anim->setRotationAngle(controllable.move.angle(Vector2f(-1, 0))); animation.setAnimIndex(0);