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/lib/wal/sources/System/System.hpp b/lib/wal/sources/System/System.hpp index 88a1c73b..2d7f544c 100644 --- a/lib/wal/sources/System/System.hpp +++ b/lib/wal/sources/System/System.hpp @@ -44,7 +44,8 @@ namespace WAL virtual void onFixedUpdate(ViewEntity &entity) {} //! @brief A method called after all entities that this system manage has been updated. - virtual void onSelfUpdate() {} + //! @param dtime The delta time. + virtual void onSelfUpdate(std::chrono::nanoseconds dtime) {} //! @brief Update the whole system (every entities that this system is responsible can be updated. @@ -53,7 +54,7 @@ namespace WAL { for (auto &entity : this->getView()) this->onUpdate(entity, dtime); - this->onSelfUpdate(); + this->onSelfUpdate(dtime); } //! @brief An alternative of update that is called every 8ms (120 times per seconds). If the system slow down, it will try to catch up. diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index 3701d816..6c3961de 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -78,7 +78,15 @@ namespace BBM .addComponent() .addComponent(1, [](WAL::Entity &entity, WAL::Wal &) { auto &animation = entity.getComponent(); + animation.setAnimIndex(5); + if (entity.hasComponent()) + entity.removeComponent(); + if (entity.hasComponent()) + return; + entity.addComponent(1s, [](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 5cd1a28d..23f312dc 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,8 +28,9 @@ namespace BBM auto drawable = entity.get().drawable.get(); auto &animation = entity.get(); auto anim = dynamic_cast(drawable); + auto health = entity->tryGetComponent(); - if (entity->shouldDelete()) + if (health && health->getHealthPoint() <= 0 || entity->shouldDelete()) return; if (anim && controllable.move != Vector2f(0, 0)) { anim->setRotationAngle(controllable.move.angle(Vector2f(-1, 0))); diff --git a/sources/System/Controllable/ControllableSystem.cpp b/sources/System/Controllable/ControllableSystem.cpp index 6916de9f..36e9815a 100644 --- a/sources/System/Controllable/ControllableSystem.cpp +++ b/sources/System/Controllable/ControllableSystem.cpp @@ -6,6 +6,7 @@ #include "ControllableSystem.hpp" #include "Component/Movable/MovableComponent.hpp" #include "Component/Controllable/ControllableComponent.hpp" +#include "Component/Health/HealthComponent.hpp" #include "Entity/Entity.hpp" namespace BBM @@ -18,8 +19,11 @@ namespace BBM { auto &controllable = entity.get(); auto &movable = entity.get(); + auto health = entity->tryGetComponent(); Vector2f move = controllable.move.normalized() * controllable.speed; + if (health && health->getHealthPoint() <= 0) + return; movable.addForce(Vector3f(move.x, 0, move.y)); } } \ No newline at end of file diff --git a/sources/System/EndCondition/EndConditionSystem.cpp b/sources/System/EndCondition/EndConditionSystem.cpp index fdabe35a..93ea2003 100644 --- a/sources/System/EndCondition/EndConditionSystem.cpp +++ b/sources/System/EndCondition/EndConditionSystem.cpp @@ -11,7 +11,7 @@ namespace BBM : System(wal) {} - void EndConditionSystem::onSelfUpdate() + void EndConditionSystem::onSelfUpdate(std::chrono::nanoseconds dtime) { unsigned int alivePlayersCount = 0; auto &view = this->_wal.getScene()->view(); @@ -20,7 +20,12 @@ namespace BBM return; for (auto &[_, scoreComponent, healthComponent]: view) alivePlayersCount += (healthComponent.getHealthPoint() != 0); - if (alivePlayersCount <= 1) - Runner::gameState.nextScene = Runner::gameState.ScoreScene; + if (alivePlayersCount <= 1) { + endConditionRate -= dtime; + if (endConditionRate <= 0ns) { + Runner::gameState.nextScene = Runner::gameState.ScoreScene; + endConditionRate = 500ms; + } + } } } \ No newline at end of file diff --git a/sources/System/EndCondition/EndConditionSystem.hpp b/sources/System/EndCondition/EndConditionSystem.hpp index edd3a9d7..38d1dc5a 100644 --- a/sources/System/EndCondition/EndConditionSystem.hpp +++ b/sources/System/EndCondition/EndConditionSystem.hpp @@ -5,14 +5,19 @@ #include "Component/Score/ScoreComponent.hpp" #include "Component/Health/HealthComponent.hpp" #include "Wal.hpp" +#include + +using namespace std::chrono_literals; namespace BBM { class EndConditionSystem : public WAL::System { public: + std::chrono::nanoseconds endConditionRate = 500ms; + //! @inherit - void onSelfUpdate() override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @brief ctor EndConditionSystem(WAL::Wal &wal); diff --git a/sources/System/Event/EventSystem.cpp b/sources/System/Event/EventSystem.cpp index da683dec..71f7d204 100644 --- a/sources/System/Event/EventSystem.cpp +++ b/sources/System/Event/EventSystem.cpp @@ -26,7 +26,7 @@ namespace BBM event(entity); } - void EventSystem::onSelfUpdate() + void EventSystem::onSelfUpdate(std::chrono::nanoseconds dtime) { for (auto &event : this->_globalEvents) event(this->_wal); diff --git a/sources/System/Event/EventSystem.hpp b/sources/System/Event/EventSystem.hpp index bcdb14c0..9d4cdfdb 100644 --- a/sources/System/Event/EventSystem.hpp +++ b/sources/System/Event/EventSystem.hpp @@ -27,7 +27,7 @@ namespace BBM //! @inherit void onUpdate(WAL::ViewEntity<> &entity, std::chrono::nanoseconds dtime) override; //! @inherit - void onSelfUpdate() override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @brief A default constructor explicit EventSystem(WAL::Wal &wal); diff --git a/sources/System/IAControllable/IAControllableSystem.cpp b/sources/System/IAControllable/IAControllableSystem.cpp index 26432c1f..cec372fc 100644 --- a/sources/System/IAControllable/IAControllableSystem.cpp +++ b/sources/System/IAControllable/IAControllableSystem.cpp @@ -172,7 +172,7 @@ namespace BBM ia._state.popLast(); } - void IAControllableSystem::onSelfUpdate() + void IAControllableSystem::onSelfUpdate(std::chrono::nanoseconds dtime) { _cached = false; _map.clear(); diff --git a/sources/System/IAControllable/IAControllableSystem.hpp b/sources/System/IAControllable/IAControllableSystem.hpp index 6c895a25..36ce9cfe 100644 --- a/sources/System/IAControllable/IAControllableSystem.hpp +++ b/sources/System/IAControllable/IAControllableSystem.hpp @@ -53,7 +53,7 @@ namespace BBM void onFixedUpdate(WAL::ViewEntity &entity) override; //! @inherit - void onSelfUpdate() override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @brief A default constructor IAControllableSystem(WAL::Wal &wal); diff --git a/sources/System/IntroAnimation/IntroAnimationSystem.cpp b/sources/System/IntroAnimation/IntroAnimationSystem.cpp index 887a11d8..9e14eb1b 100644 --- a/sources/System/IntroAnimation/IntroAnimationSystem.cpp +++ b/sources/System/IntroAnimation/IntroAnimationSystem.cpp @@ -97,7 +97,7 @@ namespace BBM component.frameCounter++; } - void IntroAnimationSystem::onSelfUpdate(void) + void IntroAnimationSystem::onSelfUpdate(std::chrono::nanoseconds) { } } \ No newline at end of file diff --git a/sources/System/IntroAnimation/IntroAnimationSystem.hpp b/sources/System/IntroAnimation/IntroAnimationSystem.hpp index 1a266443..a48c2af4 100644 --- a/sources/System/IntroAnimation/IntroAnimationSystem.hpp +++ b/sources/System/IntroAnimation/IntroAnimationSystem.hpp @@ -14,7 +14,7 @@ namespace BBM public: //! @inherit - void onSelfUpdate(void) override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @inherit void onFixedUpdate(WAL::ViewEntity &entities) override; diff --git a/sources/System/Lobby/LobbySystem.cpp b/sources/System/Lobby/LobbySystem.cpp index cbb33c7e..23e568f3 100644 --- a/sources/System/Lobby/LobbySystem.cpp +++ b/sources/System/Lobby/LobbySystem.cpp @@ -150,7 +150,7 @@ namespace BBM texture->unload(); } - void LobbySystem::onSelfUpdate() + void LobbySystem::onSelfUpdate(std::chrono::nanoseconds dtime) { auto &view = this->_wal.getScene()->view, Drawable2DComponent>(); if (view.size() == 0) diff --git a/sources/System/Lobby/LobbySystem.hpp b/sources/System/Lobby/LobbySystem.hpp index 2cbf0258..ad238ea6 100644 --- a/sources/System/Lobby/LobbySystem.hpp +++ b/sources/System/Lobby/LobbySystem.hpp @@ -32,7 +32,7 @@ namespace BBM void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override; //! @inherit - void onSelfUpdate() override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @brief Check if every player is ready. //! @param scene The lobby scene containing lobby players. diff --git a/sources/System/MenuControllable/MenuControllableSystem.cpp b/sources/System/MenuControllable/MenuControllableSystem.cpp index 96dcb341..f0115900 100644 --- a/sources/System/MenuControllable/MenuControllableSystem.cpp +++ b/sources/System/MenuControllable/MenuControllableSystem.cpp @@ -72,7 +72,7 @@ namespace BBM && (buttonPos.y <= mousePos.y && mousePos.y <= buttonPos.y + dimensions.y)); } - void MenuControllableSystem::onSelfUpdate() + void MenuControllableSystem::onSelfUpdate(std::chrono::nanoseconds dtime) { RAY::Vector2 rayMousePos = RAYControl::Mouse::getCursorPosition(); RAY::Vector2 winSize = RAY::Window::getInstance().getDimensions(); diff --git a/sources/System/MenuControllable/MenuControllableSystem.hpp b/sources/System/MenuControllable/MenuControllableSystem.hpp index 7462a358..28fe0a60 100644 --- a/sources/System/MenuControllable/MenuControllableSystem.hpp +++ b/sources/System/MenuControllable/MenuControllableSystem.hpp @@ -33,7 +33,7 @@ namespace BBM //! @brief time (in millisecond) since last check std::chrono::time_point now; //! @inherit - void onSelfUpdate() override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @brief A default constructor explicit MenuControllableSystem(WAL::Wal &wal); diff --git a/sources/System/Renderer/RenderSystem.cpp b/sources/System/Renderer/RenderSystem.cpp index 26a14275..89e8a4e5 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -102,7 +102,7 @@ namespace BBM this->_window.setDimensions(newDims); } - void RenderSystem::onSelfUpdate() + void RenderSystem::onSelfUpdate(std::chrono::nanoseconds dtime) { this->_camera.update(); this->_window.beginDrawing(); diff --git a/sources/System/Renderer/RenderSystem.hpp b/sources/System/Renderer/RenderSystem.hpp index 0d048ab2..e5679be5 100644 --- a/sources/System/Renderer/RenderSystem.hpp +++ b/sources/System/Renderer/RenderSystem.hpp @@ -46,7 +46,7 @@ namespace BBM public: //! @brief A method called after all entities that this system manage has been updated. //! @note render on screen here - void onSelfUpdate() override; + void onSelfUpdate(std::chrono::nanoseconds dtime) override; //! @inherit void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override;