mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-08 03:50:47 +00:00
timer added to speedup bonus (15s)
This commit is contained in:
@@ -8,6 +8,9 @@
|
|||||||
#include <Models/Vector2.hpp>
|
#include <Models/Vector2.hpp>
|
||||||
#include "Component/Component.hpp"
|
#include "Component/Component.hpp"
|
||||||
#include "Entity/Entity.hpp"
|
#include "Entity/Entity.hpp"
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
{
|
{
|
||||||
@@ -24,6 +27,10 @@ namespace BBM
|
|||||||
bool pause = false;
|
bool pause = false;
|
||||||
//! @brief The speed applied to every controllable entities.
|
//! @brief The speed applied to every controllable entities.
|
||||||
float speed = .25f;
|
float speed = .25f;
|
||||||
|
//! @brief The number of seconds before a speedbonus expire. This variable is used to reset the nextSpeedBonusRate value.
|
||||||
|
std::chrono::nanoseconds speedBonusRate = 15000ms;
|
||||||
|
//! @brief The number of nanosecond before the expiration of a speed bonus.
|
||||||
|
std::chrono::nanoseconds nextSpeedBonusRate = speedBonusRate;
|
||||||
|
|
||||||
//! @inherit
|
//! @inherit
|
||||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ namespace BBM {
|
|||||||
if (!player.hasComponent<MovableComponent>())
|
if (!player.hasComponent<MovableComponent>())
|
||||||
return;
|
return;
|
||||||
auto &controllable = player.getComponent<ControllableComponent>();
|
auto &controllable = player.getComponent<ControllableComponent>();
|
||||||
controllable.speed += 0.02f;
|
controllable.speed = 0.35f;
|
||||||
|
controllable.nextSpeedBonusRate = controllable.speedBonusRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Bonus::IgnoreWallsBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis)
|
void Bonus::IgnoreWallsBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis)
|
||||||
|
|||||||
@@ -14,12 +14,19 @@ namespace BBM
|
|||||||
: System(wal)
|
: System(wal)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
void ControllableSystem::onFixedUpdate(WAL::ViewEntity<ControllableComponent, MovableComponent> &entity)
|
void ControllableSystem::onUpdate(WAL::ViewEntity<ControllableComponent, MovableComponent> &entity, std::chrono::nanoseconds dtime)
|
||||||
{
|
{
|
||||||
auto &controllable = entity.get<ControllableComponent>();
|
auto &controllable = entity.get<ControllableComponent>();
|
||||||
auto &movable = entity.get<MovableComponent>();
|
auto &movable = entity.get<MovableComponent>();
|
||||||
Vector2f move = controllable.move.normalized() * controllable.speed;
|
Vector2f move = controllable.move.normalized() * controllable.speed;
|
||||||
|
|
||||||
movable.addForce(Vector3f(move.x, controllable.jump, move.y));
|
movable.addForce(Vector3f(move.x, controllable.jump, move.y));
|
||||||
|
if (controllable.speed == 0.25f)
|
||||||
|
return;
|
||||||
|
controllable.nextSpeedBonusRate -= dtime;
|
||||||
|
if (controllable.nextSpeedBonusRate <= 0ns) {
|
||||||
|
controllable.nextSpeedBonusRate = controllable.speedBonusRate;
|
||||||
|
controllable.speed = 0.25f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,14 +9,17 @@
|
|||||||
#include "Component/Controllable/ControllableComponent.hpp"
|
#include "Component/Controllable/ControllableComponent.hpp"
|
||||||
#include "System/System.hpp"
|
#include "System/System.hpp"
|
||||||
|
|
||||||
|
using namespace std::chrono_literals;
|
||||||
|
|
||||||
namespace BBM
|
namespace BBM
|
||||||
{
|
{
|
||||||
//! @brief A system to handle Controllable entities.
|
//! @brief A system to handle Controllable entities.
|
||||||
class ControllableSystem : public WAL::System<ControllableComponent, MovableComponent>
|
class ControllableSystem : public WAL::System<ControllableComponent, MovableComponent>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
//! @inherit
|
//! @inherit
|
||||||
void onFixedUpdate(WAL::ViewEntity<ControllableComponent, MovableComponent> &entity) override;
|
void onUpdate(WAL::ViewEntity<ControllableComponent, MovableComponent> &entity, std::chrono::nanoseconds dtime) override;
|
||||||
|
|
||||||
//! @brief A default constructor
|
//! @brief A default constructor
|
||||||
explicit ControllableSystem(WAL::Wal &wal);
|
explicit ControllableSystem(WAL::Wal &wal);
|
||||||
|
|||||||
Reference in New Issue
Block a user