add no clip bonus

This commit is contained in:
Askou
2021-06-15 10:35:06 +02:00
parent 513811a300
commit 2a1d56ed3b
4 changed files with 17 additions and 19 deletions
@@ -20,14 +20,12 @@ namespace BBM
std::chrono::nanoseconds speedBonusRate = 15s;
//! @brief The number of nanosecond before the expiration of a speed bonus.
std::chrono::nanoseconds nextSpeedBonusRate = speedBonusRate;
//! @brief The number of seconds before a range bonus expire. This variable is used to reset the nextRangeBonusRate value.
std::chrono::nanoseconds rangeBonusRate = 10s;
//! @brief The number of nanosecond before the expiration of a range bonus.
std::chrono::nanoseconds nextRangeBonusRate = rangeBonusRate;
//! @brief The number of seconds before a range bonus expire. This variable is used to reset the nextRangeBonusRate value.
//! @brief The number of seconds before a range bonus expire. This variable is used to reset the nextNoClipBonusRate value.
std::chrono::nanoseconds noClipBonusRate = 10s;
//! @brief The number of nanosecond before the expiration of a range bonus.
//! @brief The number of nanosecond before the expiration of a no clip bonus
std::chrono::nanoseconds nextNoClipRate = noClipBonusRate;
//! @brief To know if the player can clip through block
bool isNoClipOn = false;
//! @inherit
WAL::Component *clone(WAL::Entity &entity) const override;
+2 -3
View File
@@ -28,9 +28,7 @@ namespace BBM {
auto *playerBonus = player.tryGetComponent<PlayerBonusComponent>();
if (!bombHolder || !playerBonus)
return;
if (bombHolder->explosionRadius <= 6)
bombHolder->explosionRadius++;
playerBonus->nextRangeBonusRate = playerBonus->rangeBonusRate;
bombHolder->explosionRadius++;
}
void Bonus::SpeedUpBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis)
@@ -53,6 +51,7 @@ namespace BBM {
if (!playerBonus)
return;
playerBonus->nextNoClipRate = playerBonus->nextSpeedBonusRate;
playerBonus->isNoClipOn = true;
}
Bonus::BonusType Bonus::getRandomBonusType()
+8 -4
View File
@@ -12,7 +12,7 @@
#include "Component/Movable/MovableComponent.hpp"
#include <Component/Timer/TimerComponent.hpp>
#include <Component/Tag/TagComponent.hpp>
#include <Component/P/TagComponent.hpp>
#include "Component/Bonus/PlayerBonusComponent.hpp"
namespace RAY3D = RAY::Drawables::Drawables3D;
using namespace std::chrono_literals;
@@ -24,9 +24,12 @@ namespace BBM
CollisionComponent::CollidedAxis collidedAxis)
{
auto *mov = entity.tryGetComponent<MovableComponent>();
auto *playerBonus = entity.tryGetComponent<Pl
auto *playerBonus = entity.tryGetComponent<PlayerBonusComponent>();
if (!mov)
return;
if (playerBonus && playerBonus->isNoClipOn)
return;
if (collidedAxis & CollisionComponent::CollidedAxis::X)
mov->_velocity.x = 0;
if (collidedAxis & CollisionComponent::CollidedAxis::Y)
@@ -42,10 +45,11 @@ namespace BBM
static std::map<Bonus::BonusType, std::string> map = {
{Bonus::BonusType::BOMBSTOCK, "assets/items/bombup"},
{Bonus::BonusType::SPEEDUP, "assets/items/speedup"},
{Bonus::BonusType::EXPLOSIONINC, "assets/items/fireup"}
{Bonus::BonusType::EXPLOSIONINC, "assets/items/fireup"},
{Bonus::BonusType::NOCLIP, "assets/items/wallpass"}
};
static std::vector<std::function<void (WAL::Entity &, const WAL::Entity &, CollisionComponent::CollidedAxis)>> func = {
&Bonus::BombUpBonus, &Bonus::SpeedUpBonus, &Bonus::ExplosionRangeBonus
&Bonus::BombUpBonus, &Bonus::SpeedUpBonus, &Bonus::ExplosionRangeBonus, &Bonus::NoClipBonus
};
auto bonusType = Bonus::getRandomBonusType();
+3 -6
View File
@@ -23,13 +23,10 @@ namespace BBM
playerBonus.nextSpeedBonusRate = playerBonus.speedBonusRate;
controllable.speed = 0.25f;
}
playerBonus.nextRangeBonusRate -= dtime;
if (playerBonus.nextRangeBonusRate <= 0ns) {
playerBonus.nextRangeBonusRate = playerBonus.rangeBonusRate;
holder.explosionRadius = 3;
}
playerBonus.nextNoClipRate -= dtime;
if (playerBonus.nextNoClipRate <= 0ns)
if (playerBonus.nextNoClipRate <= 0ns) {
playerBonus.nextNoClipRate = playerBonus.noClipBonusRate;
playerBonus.isNoClipOn = false;
}
}
}