diff --git a/CMakeLists.txt b/CMakeLists.txt index 4475da2f..63493adc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,6 +93,10 @@ set(SOURCES sources/System/Animator/AnimatorSystem.hpp sources/Component/Bomb/BasicBombComponent.cpp sources/Component/Bomb/BasicBombComponent.hpp + sources/Component/Bonus/PlayerBonusComponent.hpp + sources/Component/Bonus/PlayerBonusComponent.cpp + sources/System/Bonus/PlayerBonusSystem.hpp + sources/System/Bonus/PlayerBonusSystem.cpp ) add_executable(bomberman sources/main.cpp diff --git a/sources/Component/Bonus/PlayerBonusComponent.cpp b/sources/Component/Bonus/PlayerBonusComponent.cpp new file mode 100644 index 00000000..1c1d1d31 --- /dev/null +++ b/sources/Component/Bonus/PlayerBonusComponent.cpp @@ -0,0 +1,16 @@ +// +// Created by hbenjamin on 09/06/2021. +// + +#include "PlayerBonusComponent.hpp" + +namespace BBM { + PlayerBonusComponent::PlayerBonusComponent(WAL::Entity &entity) + : WAL::Component(entity) + {} + + WAL::Component *PlayerBonusComponent::clone(WAL::Entity &entity) const + { + return new PlayerBonusComponent(entity); + } +} diff --git a/sources/Component/Bonus/PlayerBonusComponent.hpp b/sources/Component/Bonus/PlayerBonusComponent.hpp new file mode 100644 index 00000000..3c1adacc --- /dev/null +++ b/sources/Component/Bonus/PlayerBonusComponent.hpp @@ -0,0 +1,51 @@ +// +// Created by hbenjamin on 09/06/2021. +// + +#pragma once + +#include "Component/Component.hpp" +#include "Entity/Entity.hpp" +#include + +using namespace std::chrono_literals; + +namespace BBM +{ + class PlayerBonusComponent : public WAL::Component + { + public: + + //! @brief The number of seconds before a speed bonus expire. This variable is used to reset the nextSpeedBonusRate value. + 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 damage bonus expire. This variable is used to reset the nextDamageBonusRate value. + std::chrono::nanoseconds damageBonusRate = 20s; + //! @brief The number of nanosecond before the expiration of a damage bonus. + std::chrono::nanoseconds nextDamageBonusRate = damageBonusRate; + //! @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 ignoreWalls expire. This variable is used to reset the nextSpeedBonusRate value. + std::chrono::nanoseconds ignoreWallsBonusRate = 15s; + //! @brief The number of nanosecond before the expiration of a ignoreWalls bonus. + std::chrono::nanoseconds nextIgnoreWallsBonusRate = ignoreWallsBonusRate; + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief A Bonus component can't be instantiated, it should be derived. + explicit PlayerBonusComponent(WAL::Entity &entity); + + //! @brief A Bonus component can't be instantiated, it should be derived. + PlayerBonusComponent(const PlayerBonusComponent &) = default; + + //! @brief default destructor + ~PlayerBonusComponent() override = default; + + //! @brief A Bonus component can't be assigned + PlayerBonusComponent &operator=(const PlayerBonusComponent &) = delete; + }; +} \ No newline at end of file diff --git a/sources/Component/Controllable/ControllableComponent.hpp b/sources/Component/Controllable/ControllableComponent.hpp index 05bef5cc..48df8db0 100644 --- a/sources/Component/Controllable/ControllableComponent.hpp +++ b/sources/Component/Controllable/ControllableComponent.hpp @@ -27,10 +27,6 @@ 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; diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index 854563e6..b6af53d1 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "Component/Movable/MovableComponent.hpp" #include "Bonus.hpp" #include "Component/BombHolder/BombHolderComponent.hpp" @@ -25,7 +26,9 @@ namespace BBM { return; if (player.hasComponent()) { auto &bombHolder = player.getComponent(); - bombHolder.damage++; + auto &playerBonus = player.getComponent(); + bombHolder.damage = 2; + playerBonus.nextDamageBonusRate = playerBonus.damageBonusRate; } } @@ -35,7 +38,10 @@ namespace BBM { return; if (player.hasComponent()) { auto &bombHolder = player.getComponent(); - bombHolder.explosionRadius++; + auto &playerBonus = player.getComponent(); + if (bombHolder.explosionRadius <= 6) + bombHolder.explosionRadius++; + playerBonus.nextRangeBonusRate = playerBonus.rangeBonusRate; } } @@ -46,8 +52,9 @@ namespace BBM { if (!player.hasComponent()) return; auto &controllable = player.getComponent(); + auto &playerBonus = player.getComponent(); controllable.speed = 0.35f; - controllable.nextSpeedBonusRate = controllable.speedBonusRate; + playerBonus.nextSpeedBonusRate = playerBonus.speedBonusRate; } void Bonus::IgnoreWallsBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) @@ -55,7 +62,9 @@ namespace BBM { if (bonus.shouldDelete()) return; if (player.hasComponent()) { + auto &playerBonus = player.getComponent(); auto &bombHolder = player.getComponent(); + playerBonus.nextIgnoreWallsBonusRate = playerBonus.ignoreWallsBonusRate; std::cout << "Explosion is supposed to pass through walls here" << std::endl; //bombHolder.ignoreWalls = true; } diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 96c6b5f2..2fd9a5af 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -29,6 +29,8 @@ #include #include #include +#include +#include #include "Component/Animation/AnimationsComponent.hpp" #include "System/Animation/AnimationsSystem.hpp" #include "Map/Map.hpp" @@ -58,6 +60,7 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem(); } @@ -83,6 +86,7 @@ namespace BBM .addComponent(BBM::Vector3f{0.25, 0, 0.25}, BBM::Vector3f{.75, 2, .75}) .addComponent() .addComponent() + .addComponent() .addComponent(1, [](WAL::Entity &entity) { auto &animation = entity.getComponent(); animation.setAnimIndex(5); diff --git a/sources/System/Bonus/PlayerBonusSystem.cpp b/sources/System/Bonus/PlayerBonusSystem.cpp new file mode 100644 index 00000000..f8aa721f --- /dev/null +++ b/sources/System/Bonus/PlayerBonusSystem.cpp @@ -0,0 +1,42 @@ +// +// Created by hbenjamin on 09/06/2021. +// + +#include "PlayerBonusSystem.hpp" + +using namespace std::chrono_literals; + +namespace BBM +{ + PlayerBonusSystem::PlayerBonusSystem(WAL::Wal &wal) + : System(wal) + {} + + void PlayerBonusSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) + { + auto &controllable = entity.get(); + auto &holder = entity.get(); + auto &playerBonus = entity.get(); + + playerBonus.nextSpeedBonusRate -= dtime; + if (playerBonus.nextSpeedBonusRate <= 0ns) { + playerBonus.nextSpeedBonusRate = playerBonus.speedBonusRate; + controllable.speed = 0.25f; + } + playerBonus.nextIgnoreWallsBonusRate -= dtime; + if (playerBonus.nextIgnoreWallsBonusRate <= 0ns) { + playerBonus.nextIgnoreWallsBonusRate = playerBonus.ignoreWallsBonusRate; + //holder.ignoreWalls = false; + } + playerBonus.nextDamageBonusRate -= dtime; + if (playerBonus.nextDamageBonusRate <= 0ns) { + playerBonus.nextDamageBonusRate = playerBonus.damageBonusRate; + holder.damage = 1; + } + playerBonus.nextRangeBonusRate -= dtime; + if (playerBonus.nextRangeBonusRate <= 0ns) { + playerBonus.nextRangeBonusRate = playerBonus.rangeBonusRate; + holder.explosionRadius = 3; + } + } +} \ No newline at end of file diff --git a/sources/System/Bonus/PlayerBonusSystem.hpp b/sources/System/Bonus/PlayerBonusSystem.hpp new file mode 100644 index 00000000..6f0a08fa --- /dev/null +++ b/sources/System/Bonus/PlayerBonusSystem.hpp @@ -0,0 +1,34 @@ +// +// Created by hbenjamin on 09/06/2021. +// + +#pragma once + +#include +#include +#include "Models/Vector3.hpp" +#include "Component/Bonus/PlayerBonusComponent.hpp" +#include "Component/Controllable/ControllableComponent.hpp" +#include "Component/BombHolder/BombHolderComponent.hpp" + +namespace BBM +{ + //! @brief The system that allow one to place bombs. + class PlayerBonusSystem : public WAL::System + { + private: + public: + //! @inherit + void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override; + + //! @brief A default constructor + explicit PlayerBonusSystem(WAL::Wal &wal); + //! @brief A bomb holder system is copy constructable + PlayerBonusSystem(const PlayerBonusSystem &) = default; + //! @brief A default destructor + ~PlayerBonusSystem() override = default; + //! @brief A bomb holder system is not assignable. + PlayerBonusSystem &operator=(const PlayerBonusSystem &) = delete; + }; +} + diff --git a/sources/System/Controllable/ControllableSystem.cpp b/sources/System/Controllable/ControllableSystem.cpp index e0fb8b78..0714fddc 100644 --- a/sources/System/Controllable/ControllableSystem.cpp +++ b/sources/System/Controllable/ControllableSystem.cpp @@ -21,12 +21,5 @@ namespace BBM 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; - } } } \ No newline at end of file