From 1261476a0043431fca4deea02420d97684ecf6dc Mon Sep 17 00:00:00 2001 From: Askou Date: Thu, 17 Jun 2021 09:52:45 +0200 Subject: [PATCH 1/6] 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); From 811e478ca9dccea7deb742973acabe225b771275 Mon Sep 17 00:00:00 2001 From: Askou Date: Thu, 17 Jun 2021 10:09:49 +0200 Subject: [PATCH 2/6] Add a real player death --- sources/Runner/GameScene.cpp | 4 +++- sources/System/Controllable/ControllableSystem.cpp | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index f8b13f5a..4a427712 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -82,7 +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) { + if (entity.hasComponent()) + return; + entity.addComponent(1s, [](WAL::Entity &entity, WAL::Wal &wal) { entity.scheduleDeletion(); }); }); diff --git a/sources/System/Controllable/ControllableSystem.cpp b/sources/System/Controllable/ControllableSystem.cpp index 6916de9f..aeeb40d5 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->getHealthPoint() <= 0) + return; movable.addForce(Vector3f(move.x, 0, move.y)); } } \ No newline at end of file From 6ca2b902918a2bbf2c642191bdef71426744a0ad Mon Sep 17 00:00:00 2001 From: Askou Date: Thu, 17 Jun 2021 10:29:29 +0200 Subject: [PATCH 3/6] Remove controllable instead of checking health --- sources/Runner/GameScene.cpp | 3 +++ sources/System/Controllable/ControllableSystem.cpp | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index 4a427712..187d4d7e 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); + + if (entity.hasComponent()) + entity.removeComponent(); if (entity.hasComponent()) return; entity.addComponent(1s, [](WAL::Entity &entity, WAL::Wal &wal) { diff --git a/sources/System/Controllable/ControllableSystem.cpp b/sources/System/Controllable/ControllableSystem.cpp index aeeb40d5..36e9815a 100644 --- a/sources/System/Controllable/ControllableSystem.cpp +++ b/sources/System/Controllable/ControllableSystem.cpp @@ -22,7 +22,7 @@ namespace BBM auto health = entity->tryGetComponent(); Vector2f move = controllable.move.normalized() * controllable.speed; - if (health->getHealthPoint() <= 0) + if (health && health->getHealthPoint() <= 0) return; movable.addForce(Vector3f(move.x, 0, move.y)); } From 933a96c4494f9d5411067b4cd8156011d0e4cc4e Mon Sep 17 00:00:00 2001 From: Askou Date: Thu, 17 Jun 2021 10:29:56 +0200 Subject: [PATCH 4/6] fix norm --- sources/Runner/GameScene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index 187d4d7e..be14bb04 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -81,8 +81,8 @@ namespace BBM .addComponent() .addComponent(1, [](WAL::Entity &entity, WAL::Wal &) { auto &animation = entity.getComponent(); - animation.setAnimIndex(5); + animation.setAnimIndex(5); if (entity.hasComponent()) entity.removeComponent(); if (entity.hasComponent()) From 4e306581de721c0276c37f20ce8be8ad9c63c757 Mon Sep 17 00:00:00 2001 From: HENRY Benjamin Date: Thu, 17 Jun 2021 14:34:29 +0200 Subject: [PATCH 5/6] the player now see the bomb explosion before dying of it --- lib/wal/sources/System/System.hpp | 5 +++-- sources/System/EndCondition/EndConditionSystem.cpp | 11 ++++++++--- sources/System/EndCondition/EndConditionSystem.hpp | 7 ++++++- sources/System/Event/EventSystem.cpp | 2 +- sources/System/Event/EventSystem.hpp | 2 +- .../System/IntroAnimation/IntroAnimationSystem.cpp | 2 +- .../System/IntroAnimation/IntroAnimationSystem.hpp | 2 +- sources/System/Lobby/LobbySystem.cpp | 2 +- sources/System/Lobby/LobbySystem.hpp | 2 +- .../MenuControllable/MenuControllableSystem.cpp | 2 +- .../MenuControllable/MenuControllableSystem.hpp | 2 +- sources/System/Renderer/RenderSystem.cpp | 2 +- sources/System/Renderer/RenderSystem.hpp | 2 +- 13 files changed, 27 insertions(+), 16 deletions(-) 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/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/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 4d2fd563..bbf81539 100644 --- a/sources/System/Lobby/LobbySystem.cpp +++ b/sources/System/Lobby/LobbySystem.cpp @@ -149,7 +149,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 d3158774..65b4381b 100644 --- a/sources/System/MenuControllable/MenuControllableSystem.cpp +++ b/sources/System/MenuControllable/MenuControllableSystem.cpp @@ -75,7 +75,7 @@ namespace BBM && (buttonPos.y <= mousePos.y && mousePos.y <= buttonPos.y + dimensions.y)); } - void MenuControllableSystem::onSelfUpdate() + void MenuControllableSystem::onSelfUpdate(std::chrono::nanoseconds dtime) { auto &controllableView = this->_wal.getScene()->view(); diff --git a/sources/System/MenuControllable/MenuControllableSystem.hpp b/sources/System/MenuControllable/MenuControllableSystem.hpp index 67254369..f7a8edcc 100644 --- a/sources/System/MenuControllable/MenuControllableSystem.hpp +++ b/sources/System/MenuControllable/MenuControllableSystem.hpp @@ -30,7 +30,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 161bd2d8..26e2a7e0 100644 --- a/sources/System/Renderer/RenderSystem.cpp +++ b/sources/System/Renderer/RenderSystem.cpp @@ -40,7 +40,7 @@ namespace BBM drawable.drawable->drawWiresOn(this->_window); } - 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 bff17267..2e1e1404 100644 --- a/sources/System/Renderer/RenderSystem.hpp +++ b/sources/System/Renderer/RenderSystem.hpp @@ -32,7 +32,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; From c17ca81cbdaa999889eb0efe043d52aa1fc076bd Mon Sep 17 00:00:00 2001 From: HENRY Benjamin Date: Thu, 17 Jun 2021 14:44:55 +0200 Subject: [PATCH 6/6] updated selfUpdate --- sources/System/IAControllable/IAControllableSystem.cpp | 2 +- sources/System/IAControllable/IAControllableSystem.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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);