when there is only one player remaing, goes back

This commit is contained in:
arthur.jamet
2021-06-15 10:42:56 +02:00
parent 377a07cd37
commit 0bc65f2ffd
3 changed files with 49 additions and 0 deletions
+2
View File
@@ -132,6 +132,8 @@ set(SOURCES
sources/Runner/CreditScene.cpp
sources/Component/Score/ScoreComponent.cpp
sources/Component/Score/ScoreComponent.hpp
sources/System/EndCondition/EndConditionSystem.hpp
sources/System/EndCondition/EndConditionSystem.cpp
)
add_executable(bomberman
sources/main.cpp
@@ -0,0 +1,21 @@
#include "EndConditionSystem.hpp"
#include <map>
#include "Runner/Runner.hpp"
namespace BBM {
EndConditionSystem::EndConditionSystem(WAL::Wal &wal)
: System(wal)
{}
void EndConditionSystem::onSelfUpdate()
{
unsigned int alivePlayersCount = 0;
for (auto & [_ , healthComponent]: this->_wal.getScene()->view<HealthComponent>())
alivePlayersCount += (healthComponent.getHealthPoint() != 0);
if (alivePlayersCount <= 1)
Runner::gameState.nextScene = Runner::gameState.MainMenuScene;
}
}
@@ -0,0 +1,26 @@
#pragma once
#include "System/System.hpp"
#include "Component/Score/ScoreComponent.hpp"
#include "Component/Health/HealthComponent.hpp"
#include "Wal.hpp"
namespace BBM
{
class EndConditionSystem : public WAL::System<ScoreComponent, HealthComponent>
{
public:
//! @inherit
void onSelfUpdate() override;
//! @brief ctor
EndConditionSystem(WAL::Wal &wal);
//! @brief Default copy ctor
EndConditionSystem(const EndConditionSystem &) = default;
//! @brief Default dtor
~EndConditionSystem() override = default;
//! @brief A SoundManager screen system can't be assigned.
EndConditionSystem &operator=(const EndConditionSystem &) = delete;
};
}