From be48b46b7adc540b127497e4060e8ff80d45fcac Mon Sep 17 00:00:00 2001 From: Askou Date: Mon, 14 Jun 2021 16:33:42 +0200 Subject: [PATCH] add noClip to bonus.hpp --- sources/Component/Bonus/PlayerBonusComponent.hpp | 2 ++ sources/Items/Bonus.cpp | 12 ++++++++++++ sources/Items/Bonus.hpp | 8 +++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/sources/Component/Bonus/PlayerBonusComponent.hpp b/sources/Component/Bonus/PlayerBonusComponent.hpp index c6a10056..548f1158 100644 --- a/sources/Component/Bonus/PlayerBonusComponent.hpp +++ b/sources/Component/Bonus/PlayerBonusComponent.hpp @@ -24,6 +24,8 @@ namespace BBM std::chrono::nanoseconds rangeBonusRate = 10s; //! @brief The number of nanosecond before the expiration of a range bonus. std::chrono::nanoseconds nextRangeBonusRate = rangeBonusRate; + //! @brief Tell if the bonus no clip is on + bool isNoClipOn = false; //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index 47a5c2ba..6b30ecd1 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -45,6 +45,18 @@ namespace BBM { playerBonus->nextSpeedBonusRate = playerBonus->speedBonusRate; } + void Bonus::NoClipBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) + { + if (bonus.shouldDelete() || axis != 7) + return; + auto *playerBonus = player.tryGetComponent(); + if (!playerBonus) + return; + static void SpeedUSpeedUpBonuspBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis); + static void SpeedUpBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis); + playerBonus->isNoClipOn = true + } + Bonus::BonusType Bonus::getRandomBonusType() { double rnd = static_cast(std::rand()) / RAND_MAX; diff --git a/sources/Items/Bonus.hpp b/sources/Items/Bonus.hpp index 6c15efd4..2284b63f 100644 --- a/sources/Items/Bonus.hpp +++ b/sources/Items/Bonus.hpp @@ -30,11 +30,17 @@ namespace BBM { //! @brief Apply bonus effect that allows to run faster static void SpeedUpBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis); + //! @param bonus bonus + //! @param player the entity on which the effect will be applied + //! @brief Apply bonus effect that allows to pass trough breakbable walls + static void NoClipBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis); + enum BonusType { NOTHING, BOMBSTOCK, SPEEDUP, - EXPLOSIONINC + EXPLOSIONINC, + NOCLIP }; static BonusType getRandomBonusType();