mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-03 02:23:44 +00:00
Adding a restart timer when resuming the game
This commit is contained in:
@@ -15,6 +15,9 @@ namespace BBM
|
||||
class TimerComponent : public WAL::Component
|
||||
{
|
||||
public:
|
||||
//! @brief Is the ticking of this component disabled?
|
||||
bool disabled = false;
|
||||
|
||||
//! @brief The callback to call when the timer ring.
|
||||
WAL::Callback<WAL::Entity &, WAL::Wal &> callback;
|
||||
//! @brief The ring delay of this timer component.
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
#include <Wal.hpp>
|
||||
#include "Runner.hpp"
|
||||
#include <map>
|
||||
#include <System/Renderer/CameraSystem.hpp>
|
||||
#include "Component/Health/HealthComponent.hpp"
|
||||
#include "Component/Timer/TimerComponent.hpp"
|
||||
#include "Component/Tag/TagComponent.hpp"
|
||||
#include "Component/Music/MusicComponent.hpp"
|
||||
#include "Component/Sound/SoundComponent.hpp"
|
||||
#include "Component/Controllable/ControllableComponent.hpp"
|
||||
@@ -41,18 +45,39 @@ namespace BBM
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_back.png")
|
||||
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
texture->use("assets/buttons/button_back.png");
|
||||
})
|
||||
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
texture->use("assets/buttons/button_back_hovered.png");
|
||||
})
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &, WAL::Wal &)
|
||||
{
|
||||
auto &gameScene = gameState.loadedScenes[BBM::GameState::SceneID::GameScene];
|
||||
for (auto &[entity, controller, _] : gameScene->view<ControllableComponent, HealthComponent>()) {
|
||||
controller.disabled = true;
|
||||
controller.pause = false;
|
||||
controller.bomb = false;
|
||||
}
|
||||
for (auto &[_, timer] : gameScene->view<TimerComponent>())
|
||||
timer.disabled = true;
|
||||
gameScene->scheduleNewEntity("Restart timer")
|
||||
.addComponent<TimerComponent>(std::chrono::seconds(3), [gameScene](WAL::Entity &entity, WAL::Wal &) {
|
||||
for (auto &[_, controller, health] : gameScene->view<ControllableComponent, HealthComponent>()) {
|
||||
if (health.getHealthPoint() > 0)
|
||||
controller.disabled = false;
|
||||
}
|
||||
for (auto &[_, timer] : gameScene->view<TimerComponent>())
|
||||
timer.disabled = false;
|
||||
entity.scheduleDeletion();
|
||||
})
|
||||
.addComponent<PositionComponent>(1920 / 2 - 2 * 30, 1080 / 2, 0)
|
||||
.addComponent<TagComponent<"Timer">>()
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("", 60, RAY::Vector2(), ORANGE);
|
||||
gameState.nextScene = BBM::GameState::SceneID::GameScene;
|
||||
});
|
||||
auto &settings = scene->addEntity("settings button")
|
||||
@@ -79,18 +104,19 @@ namespace BBM
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/buttons/button_exit.png")
|
||||
.addComponent<OnIdleComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
texture->use("assets/buttons/button_exit.png");
|
||||
})
|
||||
.addComponent<OnHoverComponent>([](WAL::Entity &entity, WAL::Wal &)
|
||||
{
|
||||
RAY::Texture *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
auto *texture = dynamic_cast<RAY::Texture *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
texture->use("assets/buttons/button_exit_hovered.png");
|
||||
})
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &, WAL::Wal &wal)
|
||||
{
|
||||
wal.getSystem<CameraSystem>().hasEnded = false;
|
||||
gameState.nextScene = BBM::GameState::SceneID::MainMenuScene;
|
||||
});
|
||||
//needed material
|
||||
|
||||
@@ -70,8 +70,6 @@ namespace BBM
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (gameState.nextScene != GameState::SceneID::GameScene)
|
||||
engine.getSystem<CameraSystem>().hasEnded = false;
|
||||
}
|
||||
if (gameState.nextScene == gameState.currentScene)
|
||||
return;
|
||||
@@ -117,9 +115,9 @@ namespace BBM
|
||||
.addSystem<ShaderSystem>()
|
||||
.addSystem<ShaderModelSystem>()
|
||||
.addSystem<ShaderDrawable2DSystem>()
|
||||
.addSystem<EndConditionSystem>()
|
||||
.addSystem<ScoreSystem>()
|
||||
.addSystem<CameraSystem>()
|
||||
.addSystem<EndConditionSystem>()
|
||||
.addSystem<MusicSystem>();
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ namespace BBM
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("Debug Mode: Off", 70, RAY::Vector2(), BLACK)
|
||||
.addComponent<OnClickComponent>([](WAL::Entity &entity, WAL::Wal &wal)
|
||||
{
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
auto *text = dynamic_cast<RAY2D::Text *>(entity.getComponent<Drawable2DComponent>().drawable.get());
|
||||
|
||||
if (text->getString().find("Off") != std::string::npos) {
|
||||
text->setText("Debug Mode: On");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
#include "EndConditionSystem.hpp"
|
||||
#include <map>
|
||||
#include <System/Renderer/CameraSystem.hpp>
|
||||
#include "Runner/Runner.hpp"
|
||||
#include "Component/Score/ScoreComponent.hpp"
|
||||
|
||||
@@ -23,6 +24,7 @@ namespace BBM
|
||||
if (alivePlayersCount <= 1) {
|
||||
endConditionRate -= dtime;
|
||||
if (endConditionRate <= 0ns) {
|
||||
this->_wal.getSystem<CameraSystem>().hasEnded = false;
|
||||
Runner::gameState.nextScene = Runner::gameState.ScoreScene;
|
||||
endConditionRate = 500ms;
|
||||
}
|
||||
|
||||
@@ -31,9 +31,11 @@ namespace BBM
|
||||
.addComponent<PositionComponent>(1920 / 2 - 2 * 30 - 20, 28, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(Vector2f(), Vector2f(150, 60), RAY::Color(BLACK).setA(150));
|
||||
this->_wal.getScene()->scheduleNewEntity("Timer")
|
||||
.addComponent<TimerComponent>(std::chrono::minutes (3), [](WAL::Entity &, WAL::Wal &) {
|
||||
.addComponent<TimerComponent>(std::chrono::minutes (3), [](WAL::Entity &, WAL::Wal &engine) {
|
||||
engine.getSystem<CameraSystem>().hasEnded = false;
|
||||
Runner::gameState.nextScene = GameState::ScoreScene;
|
||||
})
|
||||
.addComponent<TagComponent<"Timer">>()
|
||||
.addComponent<PositionComponent>(1920 / 2 - 2 * 30, 30, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("", 60, RAY::Vector2(), ORANGE);
|
||||
for (WAL::Entity &player : this->_wal.getScene()->view<TagComponent<Player>>())
|
||||
|
||||
@@ -17,8 +17,13 @@ namespace BBM
|
||||
void TimerSystem::onUpdate(WAL::ViewEntity<TimerComponent> &entity, std::chrono::nanoseconds dtime)
|
||||
{
|
||||
auto &timer = entity.get<TimerComponent>();
|
||||
|
||||
if (timer.disabled)
|
||||
return;
|
||||
|
||||
timer.ringIn -= dtime;
|
||||
if (timer.ringIn <= 0ns) {
|
||||
timer.disabled = true;
|
||||
timer.callback(entity, this->_wal);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user