Adding a restart timer when resuming the game

This commit is contained in:
Zoe Roux
2021-06-18 17:56:34 +02:00
parent 6015b62664
commit a55b1543c9
7 changed files with 47 additions and 11 deletions
+32 -6
View File
@@ -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