From 4e306581de721c0276c37f20ce8be8ad9c63c757 Mon Sep 17 00:00:00 2001 From: HENRY Benjamin Date: Thu, 17 Jun 2021 14:34:29 +0200 Subject: [PATCH] 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;