score system update scores

This commit is contained in:
arthur.jamet
2021-06-15 10:30:58 +02:00
parent 86e4bf684c
commit 377a07cd37
4 changed files with 7 additions and 9 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ namespace BBM
{
ScoreComponent::ScoreComponent(WAL::Entity &entity)
: Component(entity),
score(PLAYING)
aliveTime(std::chrono::nanoseconds::zero())
{}
WAL::Component *ScoreComponent::clone(WAL::Entity &entity) const
+2 -3
View File
@@ -2,6 +2,7 @@
#pragma once
#include "Component/Component.hpp"
#include <chrono>
namespace BBM
{
@@ -9,10 +10,8 @@ namespace BBM
class ScoreComponent : public WAL::Component
{
public:
//! @brief score of player (4 is the looser, 1 is the winner)
enum Score {FIRST = 1, SECOND = 2, THIRD = 3, FOURTH = 4, PLAYING = -1};
//! @brief the score of the player
enum Score score;
std::chrono::nanoseconds aliveTime;
//! @inherit
WAL::Component *clone(WAL::Entity &entity) const override;
+3 -4
View File
@@ -11,10 +11,9 @@ namespace BBM {
: System(wal)
{}
void ScoreSystem::onSelfUpdate()
void ScoreSystem::onUpdate(WAL::ViewEntity<ScoreComponent, HealthComponent> &entity, std::chrono::nanoseconds dtime)
{
ScoreComponent::Score maxScore = ScoreComponent::Score::PLAYING;
for (auto &[_, score, _], this->_wal.getScene()->view<PositionComponent, CollisionComponent>())
if (entity.get<HealthComponent>().getHealthPoint())
entity.get<ScoreComponent>().aliveTime += dtime;
}
}
+1 -1
View File
@@ -12,7 +12,7 @@ namespace BBM
{
public:
//! @inherit
void onFixedUpdate(WAL::ViewEntity<ScoreComponent, HealthComponent> &entity) override;
void onUpdate(WAL::ViewEntity<ScoreComponent, HealthComponent> &entity, std::chrono::nanoseconds dtime) override;
//! @brief ctor
ScoreSystem(WAL::Wal &wal);