mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-25 23:49:03 +00:00
timer added to speedup bonus (15s)
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
#include <Models/Vector2.hpp>
|
||||
#include "Component/Component.hpp"
|
||||
#include "Entity/Entity.hpp"
|
||||
#include <chrono>
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
@@ -24,6 +27,10 @@ namespace BBM
|
||||
bool pause = false;
|
||||
//! @brief The speed applied to every controllable entities.
|
||||
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
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
@@ -46,7 +46,8 @@ namespace BBM {
|
||||
if (!player.hasComponent<MovableComponent>())
|
||||
return;
|
||||
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)
|
||||
|
||||
@@ -14,12 +14,19 @@ namespace BBM
|
||||
: 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 &movable = entity.get<MovableComponent>();
|
||||
Vector2f move = controllable.move.normalized() * controllable.speed;
|
||||
|
||||
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 "System/System.hpp"
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
//! @brief A system to handle Controllable entities.
|
||||
class ControllableSystem : public WAL::System<ControllableComponent, MovableComponent>
|
||||
{
|
||||
public:
|
||||
|
||||
//! @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
|
||||
explicit ControllableSystem(WAL::Wal &wal);
|
||||
|
||||
Reference in New Issue
Block a user