From be48b46b7adc540b127497e4060e8ff80d45fcac Mon Sep 17 00:00:00 2001 From: Askou Date: Mon, 14 Jun 2021 16:33:42 +0200 Subject: [PATCH 01/22] 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(); From 8126d4a7e4d284b9276a644c68efb3970e4ef8d8 Mon Sep 17 00:00:00 2001 From: Askou Date: Tue, 15 Jun 2021 09:25:26 +0200 Subject: [PATCH 02/22] add timer on noclipBonus --- sources/Component/Bonus/PlayerBonusComponent.hpp | 6 ++++-- sources/Items/Bonus.cpp | 6 ++---- sources/Map/Map.cpp | 3 ++- sources/System/Bonus/PlayerBonusSystem.cpp | 3 +++ 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/sources/Component/Bonus/PlayerBonusComponent.hpp b/sources/Component/Bonus/PlayerBonusComponent.hpp index 548f1158..38622327 100644 --- a/sources/Component/Bonus/PlayerBonusComponent.hpp +++ b/sources/Component/Bonus/PlayerBonusComponent.hpp @@ -24,8 +24,10 @@ 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; + //! @brief The number of seconds before a range bonus expire. This variable is used to reset the nextRangeBonusRate value. + std::chrono::nanoseconds noClipBonusRate = 10s; + //! @brief The number of nanosecond before the expiration of a range bonus. + std::chrono::nanoseconds nextNoClipRate = noClipBonusRate; //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index 6b30ecd1..fa1f2e77 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -52,9 +52,7 @@ namespace BBM { 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 + playerBonus->nextNoClipRate = playerBonus->nextSpeedBonusRate; } Bonus::BonusType Bonus::getRandomBonusType() @@ -62,7 +60,7 @@ namespace BBM { double rnd = static_cast(std::rand()) / RAND_MAX; if (rnd < 0.8) - return (static_cast(std::rand() % (EXPLOSIONINC - 1) + 1)); + return (static_cast(std::rand() % (NOCLIP - 1) + 1)); return (NOTHING); } } \ No newline at end of file diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 323fadb1..c711e8e0 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -12,6 +12,7 @@ #include "Component/Movable/MovableComponent.hpp" #include #include +#include namespace RAY3D = RAY::Drawables::Drawables3D; using namespace std::chrono_literals; @@ -23,7 +24,7 @@ namespace BBM CollisionComponent::CollidedAxis collidedAxis) { auto *mov = entity.tryGetComponent(); - + auto *playerBonus = entity.tryGetComponent Date: Tue, 15 Jun 2021 09:45:57 +0200 Subject: [PATCH 03/22] create score component --- CMakeLists.txt | 2 ++ sources/Component/Score/ScoreComponent.cpp | 16 ++++++++++++ sources/Component/Score/ScoreComponent.hpp | 29 ++++++++++++++++++++++ 3 files changed, 47 insertions(+) create mode 100644 sources/Component/Score/ScoreComponent.cpp create mode 100644 sources/Component/Score/ScoreComponent.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 64299c95..67b561e9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,6 +130,8 @@ set(SOURCES sources/Runner/PauseMenuScene.cpp sources/Runner/SettingsMenuScene.cpp sources/Runner/CreditScene.cpp + sources/Component/Score/ScoreComponent.cpp + sources/Component/Score/ScoreComponent.hpp ) add_executable(bomberman sources/main.cpp diff --git a/sources/Component/Score/ScoreComponent.cpp b/sources/Component/Score/ScoreComponent.cpp new file mode 100644 index 00000000..6fa3d776 --- /dev/null +++ b/sources/Component/Score/ScoreComponent.cpp @@ -0,0 +1,16 @@ + +#include "ScoreComponent.hpp" + +namespace BBM +{ + ScoreComponent::ScoreComponent(WAL::Entity &entity) + : Component(entity), + position() + {} + + WAL::Component *ScoreComponent::clone(WAL::Entity &entity) const + { + return new ScoreComponent(entity); + } + +} // namespace WAL \ No newline at end of file diff --git a/sources/Component/Score/ScoreComponent.hpp b/sources/Component/Score/ScoreComponent.hpp new file mode 100644 index 00000000..f44d0015 --- /dev/null +++ b/sources/Component/Score/ScoreComponent.hpp @@ -0,0 +1,29 @@ + +#pragma once + +#include "Component/Component.hpp" + +namespace BBM +{ + //! @brief A basic position component + class ScoreComponent : public WAL::Component + { + public: + //! @brief score of player (4 is the looser, 1 is the winner) + enum Score {FIRST = 1, SECOND = 2, THIRD = 3, FOURTH = 4, PLAYING = -1}; + //! @brief the score of the player + enum Score position; + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief Create a new ScoreComponent linked to a specific entity + explicit ScoreComponent(WAL::Entity &entity); + //! @brief A position component is copy constructable + ScoreComponent(const ScoreComponent &) = default; + //! @brief A default destructor + ~ScoreComponent() override = default; + //! @brief A position component is not assignable + ScoreComponent &operator=(const ScoreComponent &) = delete; + }; +} // namespace WAL \ No newline at end of file From 86e4bf684c3ef92ad31d18f3a4680ebd1f3ebba7 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 10:11:14 +0200 Subject: [PATCH 04/22] system basic --- sources/Component/Score/ScoreComponent.cpp | 2 +- sources/Component/Score/ScoreComponent.hpp | 2 +- sources/Runner/GameScene.cpp | 2 ++ sources/System/Score/ScoreSystem.cpp | 20 +++++++++++++++++ sources/System/Score/ScoreSystem.hpp | 26 ++++++++++++++++++++++ 5 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 sources/System/Score/ScoreSystem.cpp create mode 100644 sources/System/Score/ScoreSystem.hpp diff --git a/sources/Component/Score/ScoreComponent.cpp b/sources/Component/Score/ScoreComponent.cpp index 6fa3d776..a1e833a6 100644 --- a/sources/Component/Score/ScoreComponent.cpp +++ b/sources/Component/Score/ScoreComponent.cpp @@ -5,7 +5,7 @@ namespace BBM { ScoreComponent::ScoreComponent(WAL::Entity &entity) : Component(entity), - position() + score(PLAYING) {} WAL::Component *ScoreComponent::clone(WAL::Entity &entity) const diff --git a/sources/Component/Score/ScoreComponent.hpp b/sources/Component/Score/ScoreComponent.hpp index f44d0015..d36c0a6f 100644 --- a/sources/Component/Score/ScoreComponent.hpp +++ b/sources/Component/Score/ScoreComponent.hpp @@ -12,7 +12,7 @@ namespace BBM //! @brief score of player (4 is the looser, 1 is the winner) enum Score {FIRST = 1, SECOND = 2, THIRD = 3, FOURTH = 4, PLAYING = -1}; //! @brief the score of the player - enum Score position; + enum Score score; //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index 7668a043..3743f559 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -24,6 +24,7 @@ #include "Component/BumperTimer/BumperTimerComponent.hpp" #include "Model/Model.hpp" #include "Map/Map.hpp" +#include "Component/Score/ScoreComponent.hpp" namespace RAY3D = RAY::Drawables::Drawables3D; @@ -45,6 +46,7 @@ namespace BBM .addComponent(0, 1.01, 0) .addComponent("assets/player/player.iqm", true, std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) .addComponent() + .addComponent() .addComponent() .addComponent() .addComponent() diff --git a/sources/System/Score/ScoreSystem.cpp b/sources/System/Score/ScoreSystem.cpp new file mode 100644 index 00000000..02d21c23 --- /dev/null +++ b/sources/System/Score/ScoreSystem.cpp @@ -0,0 +1,20 @@ +// +// Created by Tom Augier on 05/06/2021 +// + +#include "ScoreSystem.hpp" +#include + +namespace BBM { + + ScoreSystem::ScoreSystem(WAL::Wal &wal) + : System(wal) + {} + + void ScoreSystem::onSelfUpdate() + { + ScoreComponent::Score maxScore = ScoreComponent::Score::PLAYING; + + for (auto &[_, score, _], this->_wal.getScene()->view()) + } +} \ No newline at end of file diff --git a/sources/System/Score/ScoreSystem.hpp b/sources/System/Score/ScoreSystem.hpp new file mode 100644 index 00000000..94d51ed6 --- /dev/null +++ b/sources/System/Score/ScoreSystem.hpp @@ -0,0 +1,26 @@ + +#pragma once + +#include "System/System.hpp" +#include "Component/Score/ScoreComponent.hpp" +#include "Component/Health/HealthComponent.hpp" +#include "Wal.hpp" + +namespace BBM +{ + class ScoreSystem : public WAL::System + { + public: + //! @inherit + void onFixedUpdate(WAL::ViewEntity &entity) override; + + //! @brief ctor + ScoreSystem(WAL::Wal &wal); + //! @brief Default copy ctor + ScoreSystem(const ScoreSystem &) = default; + //! @brief Default dtor + ~ScoreSystem() override = default; + //! @brief A SoundManager screen system can't be assigned. + ScoreSystem &operator=(const ScoreSystem &) = delete; + }; +} From 513811a3007e10cd3d875d1c737735ef08e6e79d Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 10:11:42 +0200 Subject: [PATCH 05/22] change texture ampping for fireup bonus --- assets/items/fireup.mtl | 1 + assets/items/fireup.obj | 18 +++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/assets/items/fireup.mtl b/assets/items/fireup.mtl index a90b6641..8c9f9b39 100644 --- a/assets/items/fireup.mtl +++ b/assets/items/fireup.mtl @@ -10,3 +10,4 @@ Ke 0.000000 0.000000 0.000000 Ni 1.000000 d 1.000000 illum 2 +map_Kd items.png diff --git a/assets/items/fireup.obj b/assets/items/fireup.obj index 8aefa489..2eab214a 100644 --- a/assets/items/fireup.obj +++ b/assets/items/fireup.obj @@ -26,18 +26,18 @@ v -0.401008 -0.084798 0.397024 v -0.401017 0.065157 0.400706 v -0.398980 -0.065157 -0.402734 v -0.398990 0.084798 -0.399052 -vt 0.001000 0.498000 -vt 0.001000 0.252000 -vt 0.124000 0.498000 -vt 0.124000 0.252000 +vt 0.001000 0.248000 +vt 0.001000 0.002000 +vt 0.124000 0.248000 +vt 0.124000 0.002000 vt 0.632244 0.754140 vt 0.648280 0.754140 vt 0.632244 0.996259 vt 0.648280 0.996259 -vt 0.124000 0.252000 -vt 0.124000 0.498000 -vt 0.001000 0.252000 -vt 0.001000 0.498000 +vt 0.124000 0.002000 +vt 0.124000 0.248000 +vt 0.001000 0.002000 +vt 0.001000 0.248000 vt 0.648280 0.996259 vt 0.632244 0.996259 vt 0.648280 0.754140 @@ -54,7 +54,7 @@ vn 0.0001 -0.9997 -0.0246 vn -0.0025 -0.0245 0.9997 vn -0.0001 0.9997 0.0246 vn 0.0025 0.0245 -0.9997 -vn 1.0000 0.0000 0.0025 +vn 1.0000 -0.0000 0.0025 vn -1.0000 0.0000 -0.0025 usemtl mat_map_ob000_item_007.005 s 1 From 377a07cd371bb0d18096c6a16317b7894490bb60 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 10:30:58 +0200 Subject: [PATCH 06/22] score system update scores --- sources/Component/Score/ScoreComponent.cpp | 2 +- sources/Component/Score/ScoreComponent.hpp | 5 ++--- sources/System/Score/ScoreSystem.cpp | 7 +++---- sources/System/Score/ScoreSystem.hpp | 2 +- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/sources/Component/Score/ScoreComponent.cpp b/sources/Component/Score/ScoreComponent.cpp index a1e833a6..b54a835d 100644 --- a/sources/Component/Score/ScoreComponent.cpp +++ b/sources/Component/Score/ScoreComponent.cpp @@ -5,7 +5,7 @@ namespace BBM { ScoreComponent::ScoreComponent(WAL::Entity &entity) : Component(entity), - score(PLAYING) + aliveTime(std::chrono::nanoseconds::zero()) {} WAL::Component *ScoreComponent::clone(WAL::Entity &entity) const diff --git a/sources/Component/Score/ScoreComponent.hpp b/sources/Component/Score/ScoreComponent.hpp index d36c0a6f..15da0650 100644 --- a/sources/Component/Score/ScoreComponent.hpp +++ b/sources/Component/Score/ScoreComponent.hpp @@ -2,6 +2,7 @@ #pragma once #include "Component/Component.hpp" +#include namespace BBM { @@ -9,10 +10,8 @@ namespace BBM class ScoreComponent : public WAL::Component { public: - //! @brief score of player (4 is the looser, 1 is the winner) - enum Score {FIRST = 1, SECOND = 2, THIRD = 3, FOURTH = 4, PLAYING = -1}; //! @brief the score of the player - enum Score score; + std::chrono::nanoseconds aliveTime; //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; diff --git a/sources/System/Score/ScoreSystem.cpp b/sources/System/Score/ScoreSystem.cpp index 02d21c23..4b32fda2 100644 --- a/sources/System/Score/ScoreSystem.cpp +++ b/sources/System/Score/ScoreSystem.cpp @@ -11,10 +11,9 @@ namespace BBM { : System(wal) {} - void ScoreSystem::onSelfUpdate() + void ScoreSystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) { - ScoreComponent::Score maxScore = ScoreComponent::Score::PLAYING; - - for (auto &[_, score, _], this->_wal.getScene()->view()) + if (entity.get().getHealthPoint()) + entity.get().aliveTime += dtime; } } \ No newline at end of file diff --git a/sources/System/Score/ScoreSystem.hpp b/sources/System/Score/ScoreSystem.hpp index 94d51ed6..33ad3c95 100644 --- a/sources/System/Score/ScoreSystem.hpp +++ b/sources/System/Score/ScoreSystem.hpp @@ -12,7 +12,7 @@ namespace BBM { public: //! @inherit - void onFixedUpdate(WAL::ViewEntity &entity) override; + void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override; //! @brief ctor ScoreSystem(WAL::Wal &wal); From 2a1d56ed3bd4d5928bd89d1fccdd225b21f26656 Mon Sep 17 00:00:00 2001 From: Askou Date: Tue, 15 Jun 2021 10:35:06 +0200 Subject: [PATCH 07/22] add no clip bonus --- sources/Component/Bonus/PlayerBonusComponent.hpp | 10 ++++------ sources/Items/Bonus.cpp | 5 ++--- sources/Map/Map.cpp | 12 ++++++++---- sources/System/Bonus/PlayerBonusSystem.cpp | 9 +++------ 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/sources/Component/Bonus/PlayerBonusComponent.hpp b/sources/Component/Bonus/PlayerBonusComponent.hpp index 38622327..9c9e55c7 100644 --- a/sources/Component/Bonus/PlayerBonusComponent.hpp +++ b/sources/Component/Bonus/PlayerBonusComponent.hpp @@ -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; diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index fa1f2e77..746876af 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -28,9 +28,7 @@ namespace BBM { auto *playerBonus = player.tryGetComponent(); 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() diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index c711e8e0..b96630df 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -12,7 +12,7 @@ #include "Component/Movable/MovableComponent.hpp" #include #include -#include +#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(); - auto *playerBonus = entity.tryGetComponent(); + 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 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> func = { - &Bonus::BombUpBonus, &Bonus::SpeedUpBonus, &Bonus::ExplosionRangeBonus + &Bonus::BombUpBonus, &Bonus::SpeedUpBonus, &Bonus::ExplosionRangeBonus, &Bonus::NoClipBonus }; auto bonusType = Bonus::getRandomBonusType(); diff --git a/sources/System/Bonus/PlayerBonusSystem.cpp b/sources/System/Bonus/PlayerBonusSystem.cpp index 20a62e4b..c5990f5b 100644 --- a/sources/System/Bonus/PlayerBonusSystem.cpp +++ b/sources/System/Bonus/PlayerBonusSystem.cpp @@ -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; + } } } \ No newline at end of file From 0bc65f2ffdba2c8ab8f7650db45fbe30d6503403 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 10:42:56 +0200 Subject: [PATCH 08/22] when there is only one player remaing, goes back --- CMakeLists.txt | 2 ++ .../EndCondition/EndConditionSystem.cpp | 21 +++++++++++++++ .../EndCondition/EndConditionSystem.hpp | 26 +++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 sources/System/EndCondition/EndConditionSystem.cpp create mode 100644 sources/System/EndCondition/EndConditionSystem.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 67b561e9..106dedef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,6 +132,8 @@ set(SOURCES sources/Runner/CreditScene.cpp sources/Component/Score/ScoreComponent.cpp sources/Component/Score/ScoreComponent.hpp + sources/System/EndCondition/EndConditionSystem.hpp + sources/System/EndCondition/EndConditionSystem.cpp ) add_executable(bomberman sources/main.cpp diff --git a/sources/System/EndCondition/EndConditionSystem.cpp b/sources/System/EndCondition/EndConditionSystem.cpp new file mode 100644 index 00000000..a34defa8 --- /dev/null +++ b/sources/System/EndCondition/EndConditionSystem.cpp @@ -0,0 +1,21 @@ + +#include "EndConditionSystem.hpp" +#include +#include "Runner/Runner.hpp" + +namespace BBM { + + EndConditionSystem::EndConditionSystem(WAL::Wal &wal) + : System(wal) + {} + + void EndConditionSystem::onSelfUpdate() + { + unsigned int alivePlayersCount = 0; + + for (auto & [_ , healthComponent]: this->_wal.getScene()->view()) + alivePlayersCount += (healthComponent.getHealthPoint() != 0); + if (alivePlayersCount <= 1) + Runner::gameState.nextScene = Runner::gameState.MainMenuScene; + } +} \ No newline at end of file diff --git a/sources/System/EndCondition/EndConditionSystem.hpp b/sources/System/EndCondition/EndConditionSystem.hpp new file mode 100644 index 00000000..edd3a9d7 --- /dev/null +++ b/sources/System/EndCondition/EndConditionSystem.hpp @@ -0,0 +1,26 @@ + +#pragma once + +#include "System/System.hpp" +#include "Component/Score/ScoreComponent.hpp" +#include "Component/Health/HealthComponent.hpp" +#include "Wal.hpp" + +namespace BBM +{ + class EndConditionSystem : public WAL::System + { + public: + //! @inherit + void onSelfUpdate() override; + + //! @brief ctor + EndConditionSystem(WAL::Wal &wal); + //! @brief Default copy ctor + EndConditionSystem(const EndConditionSystem &) = default; + //! @brief Default dtor + ~EndConditionSystem() override = default; + //! @brief A SoundManager screen system can't be assigned. + EndConditionSystem &operator=(const EndConditionSystem &) = delete; + }; +} From a2a686cdc7b9f9475c7b567c373d307d6d3fcfe3 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 10:53:59 +0200 Subject: [PATCH 09/22] add time component --- sources/Models/GameState.hpp | 1 + sources/Runner/GameScene.cpp | 5 +++++ sources/System/EndCondition/EndConditionSystem.cpp | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sources/Models/GameState.hpp b/sources/Models/GameState.hpp index 4bb271b5..cc521c00 100644 --- a/sources/Models/GameState.hpp +++ b/sources/Models/GameState.hpp @@ -26,6 +26,7 @@ namespace BBM LobbyScene, TitleScreenScene, CreditScene, + ScoreScene = MainMenuScene, }; diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index 3743f559..670e220a 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -22,6 +22,7 @@ #include "Drawables/2D/Text.hpp" #include "Component/Gravity/GravityComponent.hpp" #include "Component/BumperTimer/BumperTimerComponent.hpp" +#include "Component/Timer/TimerComponent.hpp" #include "Model/Model.hpp" #include "Map/Map.hpp" #include "Component/Score/ScoreComponent.hpp" @@ -42,6 +43,10 @@ namespace BBM {SoundComponent::BOMB, "assets/sounds/bomb_drop.ogg"}, //{SoundComponent::DEATH, "assets/sounds/death.ogg"} }; + scene->addEntity("Timer") + .addComponent(std::chrono::seconds(60), [](WAL::Entity &, WAL::Wal &) { + Runner::gameState.nextScene = GameState::ScoreScene; + }); scene->addEntity("player") .addComponent(0, 1.01, 0) .addComponent("assets/player/player.iqm", true, std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) diff --git a/sources/System/EndCondition/EndConditionSystem.cpp b/sources/System/EndCondition/EndConditionSystem.cpp index a34defa8..655322d3 100644 --- a/sources/System/EndCondition/EndConditionSystem.cpp +++ b/sources/System/EndCondition/EndConditionSystem.cpp @@ -16,6 +16,6 @@ namespace BBM { for (auto & [_ , healthComponent]: this->_wal.getScene()->view()) alivePlayersCount += (healthComponent.getHealthPoint() != 0); if (alivePlayersCount <= 1) - Runner::gameState.nextScene = Runner::gameState.MainMenuScene; + Runner::gameState.nextScene = Runner::gameState.ScoreScene; } } \ No newline at end of file From 2ec012c5671b937bcc67039844e6aef36de3a87f Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 11:16:32 +0200 Subject: [PATCH 10/22] create blank scene for score scene --- CMakeLists.txt | 1 + sources/Runner/Runner.hpp | 5 ++++ sources/Runner/ScoreScene.cpp | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 sources/Runner/ScoreScene.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b5fcb13..1c1acedd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,6 +139,7 @@ set(SOURCES sources/System/EndCondition/EndConditionSystem.hpp sources/System/EndCondition/EndConditionSystem.cpp sources/Runner/LobbyScene.cpp + sources/Runner/ScoreScene.cpp ) add_executable(bomberman sources/main.cpp diff --git a/sources/Runner/Runner.hpp b/sources/Runner/Runner.hpp index dd225e1e..e0dcee97 100644 --- a/sources/Runner/Runner.hpp +++ b/sources/Runner/Runner.hpp @@ -59,6 +59,11 @@ namespace BBM //! @brief load all data related to splash screen static std::shared_ptr loadSplashScreenScene(); + //! @brief load all data related to score scene screen + //! @param gameScene scene containing players (to know the scores) + static std::shared_ptr loadScoreScene(WAL::Scene &gameScene); + + //! @brief loads all scenes in the game state static void loadScenes(); }; diff --git a/sources/Runner/ScoreScene.cpp b/sources/Runner/ScoreScene.cpp new file mode 100644 index 00000000..b65176c1 --- /dev/null +++ b/sources/Runner/ScoreScene.cpp @@ -0,0 +1,50 @@ + +#include +#include "Runner.hpp" +#include +#include "Component/Button/ButtonComponent.hpp" +#include "Component/Music/MusicComponent.hpp" +#include "Component/Position/PositionComponent.hpp" +#include "Component/Renderer/Drawable2DComponent.hpp" +#include "Component/Sound/SoundComponent.hpp" +#include "Drawables/Texture.hpp" + +namespace RAY2D = RAY::Drawables::Drawables2D; + +namespace BBM +{ + std::shared_ptr Runner::loadScoreScene(WAL::Scene &gameScene) + { + auto scene = std::make_shared(); + static const std::map sounds = { + {SoundComponent::JUMP, "assets/sounds/click.ogg"} + }; + + scene->addEntity("Control entity") + .addComponent("assets/musics/music_result.ogg") + .addComponent(sounds); + scene->addEntity("background") + .addComponent() + .addComponent("assets/plain_menu_background.png"); + scene->addEntity("back to main menu") + .addComponent(10, 1080 - 85, 0) + .addComponent("assets/buttons/button_back.png") + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_back.png"); + }) + .addComponent([](WAL::Entity &entity, WAL::Wal &) + { + RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); + + texture->use("assets/buttons/button_back_hovered.png"); + }); + return scene; + } +} \ No newline at end of file From 005ddecf538c96f92195fd11e59568fd98b0140e Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 11:28:24 +0200 Subject: [PATCH 11/22] end condition: change scene only if scene has a player --- sources/Models/GameState.hpp | 2 +- sources/Runner/Runner.cpp | 4 ++++ sources/Runner/ScoreScene.cpp | 3 ++- sources/System/EndCondition/EndConditionSystem.cpp | 6 +++++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/sources/Models/GameState.hpp b/sources/Models/GameState.hpp index cc521c00..da17fdc1 100644 --- a/sources/Models/GameState.hpp +++ b/sources/Models/GameState.hpp @@ -26,7 +26,7 @@ namespace BBM LobbyScene, TitleScreenScene, CreditScene, - ScoreScene = MainMenuScene, + ScoreScene, }; diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 6af5e04c..312d1213 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -34,6 +34,7 @@ #include "System/BumperTimer/BumperTimerSystem.hpp" #include "System/Music/MusicSystem.hpp" #include "System/Lobby/LobbySystem.hpp" +#include "System/EndCondition/EndConditionSystem.hpp" #include "Component/Lobby/LobbyComponent.hpp" namespace BBM @@ -58,6 +59,8 @@ namespace BBM } if (gameState.nextScene == gameState.currentScene) return; + if (gameState.nextScene == GameState::SceneID::ScoreScene) + gameState._loadedScenes[GameState::SceneID::ScoreScene] = Runner::loadScoreScene(*engine.getScene()); gameState._loadedScenes[gameState.currentScene] = engine.getScene(); engine.changeScene(gameState._loadedScenes[gameState.nextScene]); gameState.currentScene = gameState.nextScene; @@ -84,6 +87,7 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem(); } diff --git a/sources/Runner/ScoreScene.cpp b/sources/Runner/ScoreScene.cpp index b65176c1..90368250 100644 --- a/sources/Runner/ScoreScene.cpp +++ b/sources/Runner/ScoreScene.cpp @@ -20,7 +20,8 @@ namespace BBM {SoundComponent::JUMP, "assets/sounds/click.ogg"} }; - scene->addEntity("Control entity") + addMenuControl(*scene); + scene->addEntity("Audio ressources") .addComponent("assets/musics/music_result.ogg") .addComponent(sounds); scene->addEntity("background") diff --git a/sources/System/EndCondition/EndConditionSystem.cpp b/sources/System/EndCondition/EndConditionSystem.cpp index 655322d3..0403d3a1 100644 --- a/sources/System/EndCondition/EndConditionSystem.cpp +++ b/sources/System/EndCondition/EndConditionSystem.cpp @@ -2,6 +2,7 @@ #include "EndConditionSystem.hpp" #include #include "Runner/Runner.hpp" +#include "Component/Score/ScoreComponent.hpp" namespace BBM { @@ -12,8 +13,11 @@ namespace BBM { void EndConditionSystem::onSelfUpdate() { unsigned int alivePlayersCount = 0; + auto &view = this->_wal.getScene()->view(); - for (auto & [_ , healthComponent]: this->_wal.getScene()->view()) + if (!view.size()) + return; + for (auto & [_ , scoreComponent, healthComponent]: view) alivePlayersCount += (healthComponent.getHealthPoint() != 0); if (alivePlayersCount <= 1) Runner::gameState.nextScene = Runner::gameState.ScoreScene; From de767e684d25096b4c0e3a4846ec0080063ab2d3 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 11:38:44 +0200 Subject: [PATCH 12/22] add tiles to score scene --- sources/Runner/ScoreScene.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sources/Runner/ScoreScene.cpp b/sources/Runner/ScoreScene.cpp index 90368250..d7edcfab 100644 --- a/sources/Runner/ScoreScene.cpp +++ b/sources/Runner/ScoreScene.cpp @@ -19,6 +19,9 @@ namespace BBM static const std::map sounds = { {SoundComponent::JUMP, "assets/sounds/click.ogg"} }; + static const std::vector tilesColor = { + GOLD, GRAY, BROWN, PURPLE + }; addMenuControl(*scene); scene->addEntity("Audio ressources") @@ -27,6 +30,14 @@ namespace BBM scene->addEntity("background") .addComponent() .addComponent("assets/plain_menu_background.png"); + for (int i = 0; i < 4; i++) { + auto &playerTile = scene->addEntity("player tile") + .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.5, 0) + .addComponent(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), RAY::Vector2(200, 200),tilesColor[i]); + auto &player = scene->addEntity("player") + .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.5, 0) + .addComponent("assets/player/icons/none.png"); + } scene->addEntity("back to main menu") .addComponent(10, 1080 - 85, 0) .addComponent("assets/buttons/button_back.png") From eefc560a8102414f3b3da0fea6108ff3509500a1 Mon Sep 17 00:00:00 2001 From: Askou Date: Tue, 15 Jun 2021 11:56:02 +0200 Subject: [PATCH 13/22] fix random chance of bonuses --- sources/Items/Bonus.cpp | 2 +- sources/Map/Map.cpp | 24 ++++++++++++++++++++---- sources/Map/Map.hpp | 4 ++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index 23c53ef6..32267389 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -58,7 +58,7 @@ namespace BBM { { double rnd = static_cast(std::rand()) / RAND_MAX; - if (rnd <= 1) + if (rnd <= 0.8) return (static_cast((std::rand() % NOCLIP) + 1)); return (NOTHING); } diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index fb19fb24..e2e3b5de 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -44,6 +44,22 @@ namespace BBM return; health->takeDmg(health->getHealthPoint()); } + + void MapGenerator::wallYouShouldNotPass(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis) + { + auto *mov = entity.tryGetComponent(); + + if (!mov) + return; + if (collidedAxis & CollisionComponent::CollidedAxis::X) + mov->_velocity.x = 0; + if (collidedAxis & CollisionComponent::CollidedAxis::Y) + mov->_velocity.y = 0; + if (collidedAxis & CollisionComponent::CollidedAxis::Z) + mov->_velocity.z = 0; + } void MapGenerator::wallCollided(WAL::Entity &entity, const WAL::Entity &wall, @@ -161,7 +177,7 @@ namespace BBM .addComponent(Vector3f((width + 1) / 2, 0, -1)) .addComponent( WAL::Callback(), - &MapGenerator::wallCollided, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) + &MapGenerator::wallYouShouldNotPass, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) .addComponent(unbreakableObj, false, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 1)); @@ -169,7 +185,7 @@ namespace BBM .addComponent(Vector3f((width + 1) / 2, 0, height + 1)) .addComponent( WAL::Callback(), - &MapGenerator::wallCollided, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) + &MapGenerator::wallYouShouldNotPass, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) .addComponent(unbreakableObj, false, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 1)); @@ -177,7 +193,7 @@ namespace BBM .addComponent(Vector3f(width + 1, 0, height / 2)) .addComponent( WAL::Callback(), - &MapGenerator::wallCollided, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) + &MapGenerator::wallYouShouldNotPass, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) .addComponent(unbreakableObj, false, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 1)); @@ -185,7 +201,7 @@ namespace BBM .addComponent(Vector3f(-1, 0, height / 2)) .addComponent( WAL::Callback(), - &MapGenerator::wallCollided, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) + &MapGenerator::wallYouShouldNotPass, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) .addComponent(unbreakableObj, false, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 1)); diff --git a/sources/Map/Map.hpp b/sources/Map/Map.hpp index f7eef37c..87757813 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -175,6 +175,10 @@ namespace BBM static const std::string secondFloorHolePath; public: + + static void wallYouShouldNotPass(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis); static void wallCollided(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis); From bb2a9ec0817a2cea638ccea55a9c02aad1087b27 Mon Sep 17 00:00:00 2001 From: Askou Date: Tue, 15 Jun 2021 11:58:53 +0200 Subject: [PATCH 14/22] add enum for all collision --- sources/Component/Collision/CollisionComponent.hpp | 3 ++- sources/Items/Bonus.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/sources/Component/Collision/CollisionComponent.hpp b/sources/Component/Collision/CollisionComponent.hpp index e4244a7a..0190a56a 100644 --- a/sources/Component/Collision/CollisionComponent.hpp +++ b/sources/Component/Collision/CollisionComponent.hpp @@ -19,7 +19,8 @@ namespace BBM enum CollidedAxis { X = 1, Y = 2, - Z = 4 + Z = 4, + ALL = 7 }; //! @brief onCollide functions to be called diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index 32267389..f21cf1b4 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -12,7 +12,7 @@ namespace BBM { void Bonus::BombUpBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) { - if (bonus.shouldDelete() || axis != 7) + if (bonus.shouldDelete() || axis != CollisionComponent::CollidedAxis::ALL) return; auto *bombHolder = player.tryGetComponent(); if (!bombHolder) @@ -22,7 +22,7 @@ namespace BBM { void Bonus::ExplosionRangeBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) { - if (bonus.shouldDelete() || axis != 7) + if (bonus.shouldDelete() || axis != CollisionComponent::CollidedAxis::ALL) return; auto *bombHolder = player.tryGetComponent(); auto *playerBonus = player.tryGetComponent(); @@ -33,7 +33,7 @@ namespace BBM { void Bonus::SpeedUpBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) { - if (bonus.shouldDelete() || axis != 7) + if (bonus.shouldDelete() || axis != CollisionComponent::CollidedAxis::ALL) return; auto *controllable = player.tryGetComponent(); auto *playerBonus = player.tryGetComponent(); @@ -45,7 +45,7 @@ namespace BBM { void Bonus::NoClipBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) { - if (bonus.shouldDelete() || axis != 7) + if (bonus.shouldDelete() || axis != CollisionComponent::CollidedAxis::ALL) return; auto *playerBonus = player.tryGetComponent(); if (!playerBonus) From c2e857ad7a4936342e710e31f982fe49538d7eaa Mon Sep 17 00:00:00 2001 From: Askou Date: Tue, 15 Jun 2021 12:22:44 +0200 Subject: [PATCH 15/22] change player speed --- sources/Component/Bonus/PlayerBonusComponent.hpp | 5 ----- .../Component/Controllable/ControllableComponent.hpp | 2 +- sources/Items/Bonus.cpp | 11 +++++++---- sources/System/Bonus/PlayerBonusSystem.cpp | 5 ----- 4 files changed, 8 insertions(+), 15 deletions(-) diff --git a/sources/Component/Bonus/PlayerBonusComponent.hpp b/sources/Component/Bonus/PlayerBonusComponent.hpp index a93b8273..fadcc19d 100644 --- a/sources/Component/Bonus/PlayerBonusComponent.hpp +++ b/sources/Component/Bonus/PlayerBonusComponent.hpp @@ -15,11 +15,6 @@ 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 range bonus expire. This variable is used to reset the nextNoClipBonusRate value. std::chrono::nanoseconds noClipBonusRate = 5s; //! @brief The number of nanosecond before the expiration of a no clip bonus diff --git a/sources/Component/Controllable/ControllableComponent.hpp b/sources/Component/Controllable/ControllableComponent.hpp index 48df8db0..2d62a8e8 100644 --- a/sources/Component/Controllable/ControllableComponent.hpp +++ b/sources/Component/Controllable/ControllableComponent.hpp @@ -26,7 +26,7 @@ namespace BBM //! @brief input value for pause bool pause = false; //! @brief The speed applied to every controllable entities. - float speed = .25f; + float speed = .15f; //! @inherit WAL::Component *clone(WAL::Entity &entity) const override; diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index f21cf1b4..9c63e266 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -18,6 +18,7 @@ namespace BBM { if (!bombHolder) return; bombHolder->maxBombCount++; + std::cout << "BombHolder : " << bombHolder->maxBombCount << std::endl; } void Bonus::ExplosionRangeBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) @@ -29,6 +30,7 @@ namespace BBM { if (!bombHolder || !playerBonus) return; bombHolder->explosionRadius++; + std::cout << "BombRadius : " << bombHolder->explosionRadius << std::endl; } void Bonus::SpeedUpBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) @@ -39,8 +41,8 @@ namespace BBM { auto *playerBonus = player.tryGetComponent(); if (!controllable || !playerBonus) return; - controllable->speed = 0.35f; - playerBonus->nextSpeedBonusRate = playerBonus->speedBonusRate; + controllable->speed += 0.05f; + std::cout << "Speed : " << controllable->speed << std::endl; } void Bonus::NoClipBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) @@ -50,7 +52,7 @@ namespace BBM { auto *playerBonus = player.tryGetComponent(); if (!playerBonus) return; - playerBonus->nextNoClipRate = playerBonus->nextSpeedBonusRate; + playerBonus->nextNoClipRate = playerBonus->noClipBonusRate; playerBonus->isNoClipOn = true; } @@ -58,7 +60,8 @@ namespace BBM { { double rnd = static_cast(std::rand()) / RAND_MAX; - if (rnd <= 0.8) + std::cout << "Random" << rnd << std::endl; + if (rnd <= 1) return (static_cast((std::rand() % NOCLIP) + 1)); return (NOTHING); } diff --git a/sources/System/Bonus/PlayerBonusSystem.cpp b/sources/System/Bonus/PlayerBonusSystem.cpp index c5990f5b..a0fc8218 100644 --- a/sources/System/Bonus/PlayerBonusSystem.cpp +++ b/sources/System/Bonus/PlayerBonusSystem.cpp @@ -18,11 +18,6 @@ namespace BBM auto &holder = entity.get(); auto &playerBonus = entity.get(); - playerBonus.nextSpeedBonusRate -= dtime; - if (playerBonus.nextSpeedBonusRate <= 0ns) { - playerBonus.nextSpeedBonusRate = playerBonus.speedBonusRate; - controllable.speed = 0.25f; - } playerBonus.nextNoClipRate -= dtime; if (playerBonus.nextNoClipRate <= 0ns) { playerBonus.nextNoClipRate = playerBonus.noClipBonusRate; From a0784875d36a48e8733a1010e930f60523b5888b Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 12:31:44 +0200 Subject: [PATCH 16/22] sorting scores --- CMakeLists.txt | 2 ++ lib/Ray/sources/Drawables/Texture.cpp | 5 ++++ lib/Ray/sources/Drawables/Texture.hpp | 3 +++ lib/Ray/sources/Model/Model.cpp | 5 ++++ lib/Ray/sources/Model/Model.hpp | 4 +++ sources/Runner/Runner.cpp | 2 ++ sources/Runner/ScoreScene.cpp | 35 +++++++++++++++++++++++++-- 7 files changed, 54 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c1acedd..902a507b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -136,6 +136,8 @@ set(SOURCES sources/Runner/CreditScene.cpp sources/Component/Score/ScoreComponent.cpp sources/Component/Score/ScoreComponent.hpp + sources/System/Score/ScoreSystem.cpp + sources/System/Score/ScoreSystem.hpp sources/System/EndCondition/EndConditionSystem.hpp sources/System/EndCondition/EndConditionSystem.cpp sources/Runner/LobbyScene.cpp diff --git a/lib/Ray/sources/Drawables/Texture.cpp b/lib/Ray/sources/Drawables/Texture.cpp index 7a70a459..ce16a6f1 100644 --- a/lib/Ray/sources/Drawables/Texture.cpp +++ b/lib/Ray/sources/Drawables/Texture.cpp @@ -42,6 +42,11 @@ namespace RAY { return *this; } + const std::string &Texture::getResourcePath() const + { + return this->_resourcePath; + } + Texture::operator ::Texture() const { return *this->_texture; diff --git a/lib/Ray/sources/Drawables/Texture.hpp b/lib/Ray/sources/Drawables/Texture.hpp index 74eab4c8..04518c57 100644 --- a/lib/Ray/sources/Drawables/Texture.hpp +++ b/lib/Ray/sources/Drawables/Texture.hpp @@ -44,6 +44,9 @@ namespace RAY //! @brief Load texture from file, lets one use one entity for multiple files Texture &use(const std::string &filename); + //! @return path of loaded texture + const std::string &getResourcePath() const; + protected: private: //! @brief Texture, really, that's just it... diff --git a/lib/Ray/sources/Model/Model.cpp b/lib/Ray/sources/Model/Model.cpp index fefa29ea..c758ba00 100644 --- a/lib/Ray/sources/Model/Model.cpp +++ b/lib/Ray/sources/Model/Model.cpp @@ -61,6 +61,11 @@ namespace RAY::Drawables::Drawables3D return true; } + Texture &Model::getTextureByMaterial(MaterialType materialType) + { + return this->_textureList[materialType]; + } + Model::operator ::Model() const { return *this->_model; diff --git a/lib/Ray/sources/Model/Model.hpp b/lib/Ray/sources/Model/Model.hpp index 2bf6cf47..16616fb8 100644 --- a/lib/Ray/sources/Model/Model.hpp +++ b/lib/Ray/sources/Model/Model.hpp @@ -90,6 +90,10 @@ namespace RAY::Drawables::Drawables3D { //! @brief Draw model's wires on window void drawWiresOn(RAY::Window &) override; + //! @param materialType type of material + //! @return texture + Texture &getTextureByMaterial(MaterialType materialType); + private: //! @brief Raw data from raylib std::shared_ptr<::Model> _model; diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 312d1213..fe37386c 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -34,6 +34,7 @@ #include "System/BumperTimer/BumperTimerSystem.hpp" #include "System/Music/MusicSystem.hpp" #include "System/Lobby/LobbySystem.hpp" +#include "System/Score/ScoreSystem.hpp" #include "System/EndCondition/EndConditionSystem.hpp" #include "Component/Lobby/LobbyComponent.hpp" @@ -88,6 +89,7 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem(); } diff --git a/sources/Runner/ScoreScene.cpp b/sources/Runner/ScoreScene.cpp index d7edcfab..a80f3caf 100644 --- a/sources/Runner/ScoreScene.cpp +++ b/sources/Runner/ScoreScene.cpp @@ -6,22 +6,44 @@ #include "Component/Music/MusicComponent.hpp" #include "Component/Position/PositionComponent.hpp" #include "Component/Renderer/Drawable2DComponent.hpp" +#include "Component/Renderer/Drawable3DComponent.hpp" #include "Component/Sound/SoundComponent.hpp" #include "Drawables/Texture.hpp" +#include "Drawables/2D/Text.hpp" +#include "Component/Score/ScoreComponent.hpp" +#include "Model/Model.hpp" namespace RAY2D = RAY::Drawables::Drawables2D; +namespace RAY3D = RAY::Drawables::Drawables3D; namespace BBM { std::shared_ptr Runner::loadScoreScene(WAL::Scene &gameScene) { auto scene = std::make_shared(); + std::vector playersIconPath; + std::vector>players; static const std::map sounds = { {SoundComponent::JUMP, "assets/sounds/click.ogg"} }; static const std::vector tilesColor = { GOLD, GRAY, BROWN, PURPLE }; + static const std::vector rankName = { + "1st", "2nd", "3rd", "4th" + }; + + for (auto &[entity, score, drawable]: gameScene.view()) + players.push_back(entity); + std::sort(players.begin(), players.end(), [](WAL::Entity &entityA, WAL::Entity &entityB) { + return entityA.getComponent().aliveTime > entityB.getComponent().aliveTime; + }); + + for (auto &entity: players) { + RAY3D::Model *model = dynamic_cast(entity.get().getComponent().drawable.get()); + std::string path = model->getTextureByMaterial(MAP_DIFFUSE).getResourcePath(); + playersIconPath.push_back(path.replace(path.find("textures"), std::string("textures").size(), "icons")); + } addMenuControl(*scene); scene->addEntity("Audio ressources") @@ -30,13 +52,22 @@ namespace BBM scene->addEntity("background") .addComponent() .addComponent("assets/plain_menu_background.png"); - for (int i = 0; i < 4; i++) { + scene->addEntity("scene title text") + .addComponent(1920 / 3.25, 100, 0) + .addComponent("GAME OVER", 120, RAY::Vector2(), ORANGE); + scene->addEntity("scene title text") + .addComponent(1920 / 2.37, 250, 0) + .addComponent("CONGRATS", 50, RAY::Vector2(), ORANGE); + for (int i = 0; i < players.size(); i++) { auto &playerTile = scene->addEntity("player tile") .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.5, 0) .addComponent(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), RAY::Vector2(200, 200),tilesColor[i]); + auto &playerRank = scene->addEntity("player rank name") + .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.75, 0) + .addComponent(rankName[i], 30, RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), tilesColor[i]); auto &player = scene->addEntity("player") .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.5, 0) - .addComponent("assets/player/icons/none.png"); + .addComponent(playersIconPath[i]); } scene->addEntity("back to main menu") .addComponent(10, 1080 - 85, 0) From baac958615b493d5eb55eddf1bbcd6a49bd68951 Mon Sep 17 00:00:00 2001 From: Askou Date: Tue, 15 Jun 2021 14:29:08 +0200 Subject: [PATCH 17/22] change collision with bomb --- sources/Items/Bonus.cpp | 5 +---- sources/Models/Vector3.hpp | 15 +++++++++++++++ sources/System/Bomb/BombSystem.cpp | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index 9c63e266..5ba27b15 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -18,7 +18,6 @@ namespace BBM { if (!bombHolder) return; bombHolder->maxBombCount++; - std::cout << "BombHolder : " << bombHolder->maxBombCount << std::endl; } void Bonus::ExplosionRangeBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) @@ -42,7 +41,6 @@ namespace BBM { if (!controllable || !playerBonus) return; controllable->speed += 0.05f; - std::cout << "Speed : " << controllable->speed << std::endl; } void Bonus::NoClipBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) @@ -60,8 +58,7 @@ namespace BBM { { double rnd = static_cast(std::rand()) / RAND_MAX; - std::cout << "Random" << rnd << std::endl; - if (rnd <= 1) + if (rnd <= 0.8) return (static_cast((std::rand() % NOCLIP) + 1)); return (NOTHING); } diff --git a/sources/Models/Vector3.hpp b/sources/Models/Vector3.hpp index 8e8b4093..d1d1d919 100644 --- a/sources/Models/Vector3.hpp +++ b/sources/Models/Vector3.hpp @@ -168,6 +168,21 @@ namespace BBM return (point * this) / std::pow(this->magnitude(), 2) * this; } + Vector3 trunc() const requires(std::is_floating_point_v) + { + return Vector3(std::trunc(this->x), std::trunc(this->y), std::trunc(this->z)); + } + + Vector3 ceil() const requires(std::is_floating_point_v) + { + return Vector3(std::ceil(this->x), std::ceil(this->y), std::ceil(this->z)); + } + + Vector3 floor() const requires(std::is_floating_point_v) + { + return Vector3(std::floor(this->x), std::floor(this->y), std::floor(this->z)); + } + Vector3 round() const requires(std::is_floating_point_v) { return Vector3(std::round(this->x), std::round(this->y), std::round(this->z)); diff --git a/sources/System/Bomb/BombSystem.cpp b/sources/System/Bomb/BombSystem.cpp index 6049c874..60ff5a30 100644 --- a/sources/System/Bomb/BombSystem.cpp +++ b/sources/System/Bomb/BombSystem.cpp @@ -20,7 +20,7 @@ namespace BBM for (auto &[owner, ownerPos, _] : this->_wal.getScene()->view()) { if (owner.getUid() != bomb.ownerID) continue; - if (pos.position != ownerPos.position.round()) { + if (pos.position.distance(ownerPos.position) >= 1.1) { bomb.ignoreOwner = false; return; } From 11370c890dcf0a13c1890936a79381b2e45300d7 Mon Sep 17 00:00:00 2001 From: Askou Date: Tue, 15 Jun 2021 14:35:59 +0200 Subject: [PATCH 18/22] Add permanent bonuses except for wallpass --- sources/Items/Bonus.cpp | 1 - sources/System/BombHolder/BombHolderSystem.cpp | 2 -- 2 files changed, 3 deletions(-) diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index 5ba27b15..075216ef 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -29,7 +29,6 @@ namespace BBM { if (!bombHolder || !playerBonus) return; bombHolder->explosionRadius++; - std::cout << "BombRadius : " << bombHolder->explosionRadius << std::endl; } void Bonus::SpeedUpBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) diff --git a/sources/System/BombHolder/BombHolderSystem.cpp b/sources/System/BombHolder/BombHolderSystem.cpp index d67f16c7..e7b385a1 100644 --- a/sources/System/BombHolder/BombHolderSystem.cpp +++ b/sources/System/BombHolder/BombHolderSystem.cpp @@ -111,8 +111,6 @@ namespace BBM MAP_DIFFUSE, "assets/bombs/bomb_normal.png" )); - holder.damage = 1; - holder.explosionRadius = 3; } void From 2c42af1c5987c1e7c2802e8fb6f0cce04a40a573 Mon Sep 17 00:00:00 2001 From: Askou Date: Tue, 15 Jun 2021 14:59:51 +0200 Subject: [PATCH 19/22] lower speed boost value --- sources/Items/Bonus.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index 075216ef..a543395b 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -39,7 +39,7 @@ namespace BBM { auto *playerBonus = player.tryGetComponent(); if (!controllable || !playerBonus) return; - controllable->speed += 0.05f; + controllable->speed += 0.025f; } void Bonus::NoClipBonus(WAL::Entity &player, const WAL::Entity &bonus, CollisionComponent::CollidedAxis axis) From d795f367470b54081bf25a1a740a96f51c5a5f10 Mon Sep 17 00:00:00 2001 From: Askou Date: Tue, 15 Jun 2021 15:56:27 +0200 Subject: [PATCH 20/22] distri for bonus --- sources/Items/Bonus.cpp | 21 +++++++++++++++++---- sources/Map/Map.cpp | 20 ++++++-------------- sources/Map/Map.hpp | 6 +++--- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/sources/Items/Bonus.cpp b/sources/Items/Bonus.cpp index a543395b..17266a5f 100644 --- a/sources/Items/Bonus.cpp +++ b/sources/Items/Bonus.cpp @@ -7,6 +7,8 @@ #include #include "Component/Movable/MovableComponent.hpp" #include "Bonus.hpp" +#include +#include #include "Component/BombHolder/BombHolderComponent.hpp" namespace BBM { @@ -55,10 +57,21 @@ namespace BBM { Bonus::BonusType Bonus::getRandomBonusType() { - double rnd = static_cast(std::rand()) / RAND_MAX; + static std::default_random_engine generator(time(nullptr)); + std::map chanceValue = { + {NOTHING, 100.0f}, + {SPEEDUP, 45.0f}, + {BOMBSTOCK, 30.0f}, + {EXPLOSIONINC, 15.0f}, + {NOCLIP, 1.5f}, + }; + std::uniform_int_distribution distribution(1,1000); + float value = (distribution(generator) / 10); + BonusType bonus = NOTHING; - if (rnd <= 0.8) - return (static_cast((std::rand() % NOCLIP) + 1)); - return (NOTHING); + for (auto &chance : chanceValue) + if (chance.second > value) + bonus = chance.first; + return (bonus); } } \ No newline at end of file diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index 2128c39c..acdaa08f 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -45,7 +45,7 @@ namespace BBM health->takeDmg(health->getHealthPoint()); } - void MapGenerator::wallYouShouldNotPass(WAL::Entity &entity, + void MapGenerator::wallCollision(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis) { @@ -65,19 +65,11 @@ namespace BBM const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis) { - auto *mov = entity.tryGetComponent(); auto *playerBonus = entity.tryGetComponent(); - if (!mov) - return; if (playerBonus && playerBonus->isNoClipOn) return; - if (collidedAxis & CollisionComponent::CollidedAxis::X) - mov->_velocity.x = 0; - if (collidedAxis & CollisionComponent::CollidedAxis::Y) - mov->_velocity.y = 0; - if (collidedAxis & CollisionComponent::CollidedAxis::Z) - mov->_velocity.z = 0; + wallCollision(entity, wall, collidedAxis); } void MapGenerator::wallDestroyed(WAL::Entity &entity, WAL::Wal &wal) @@ -177,7 +169,7 @@ namespace BBM .addComponent(Vector3f((width + 1) / 2, 0, -1)) .addComponent( WAL::Callback(), - &MapGenerator::wallYouShouldNotPass, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) + &MapGenerator::wallCollision, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) .addComponent(unbreakableObj, false, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 1)); @@ -185,7 +177,7 @@ namespace BBM .addComponent(Vector3f((width + 1) / 2, 0, height + 1)) .addComponent( WAL::Callback(), - &MapGenerator::wallYouShouldNotPass, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) + &MapGenerator::wallCollision, Vector3f(-(width + 1) / 2 , 0.25, 0.25), Vector3f(width + 1, 2, 0.75)) .addComponent(unbreakableObj, false, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(width + 3, 1, 1)); @@ -193,7 +185,7 @@ namespace BBM .addComponent(Vector3f(width + 1, 0, height / 2)) .addComponent( WAL::Callback(), - &MapGenerator::wallYouShouldNotPass, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) + &MapGenerator::wallCollision, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) .addComponent(unbreakableObj, false, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 1)); @@ -201,7 +193,7 @@ namespace BBM .addComponent(Vector3f(-1, 0, height / 2)) .addComponent( WAL::Callback(), - &MapGenerator::wallYouShouldNotPass, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) + &MapGenerator::wallCollision, Vector3f(0.25, 0.25, -(height + 1) / 2 ), Vector3f(0.75, 2, height + 1)) .addComponent(unbreakableObj, false, std::make_pair(MAP_DIFFUSE, unbreakablePnj), RAY::Vector3(1, 1, height + 1)); diff --git a/sources/Map/Map.hpp b/sources/Map/Map.hpp index 87757813..e04a00fc 100644 --- a/sources/Map/Map.hpp +++ b/sources/Map/Map.hpp @@ -176,9 +176,9 @@ namespace BBM public: - static void wallYouShouldNotPass(WAL::Entity &entity, - const WAL::Entity &wall, - CollisionComponent::CollidedAxis collidedAxis); + static void wallCollision(WAL::Entity &entity, + const WAL::Entity &wall, + CollisionComponent::CollidedAxis collidedAxis); static void wallCollided(WAL::Entity &entity, const WAL::Entity &wall, CollisionComponent::CollidedAxis collidedAxis); From 3dfef8a0b3811e4586c53a96025969f671ac4acb Mon Sep 17 00:00:00 2001 From: Askou Date: Tue, 15 Jun 2021 16:55:45 +0200 Subject: [PATCH 21/22] fix collision --- screenshot000.png | Bin 0 -> 82420 bytes sources/Map/Map.cpp | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 screenshot000.png diff --git a/screenshot000.png b/screenshot000.png new file mode 100644 index 0000000000000000000000000000000000000000..e4060bf1c23c5d11d6397ecd306201439e42a350 GIT binary patch literal 82420 zcmeI&KWkrA0LS5L37QlOj#5w%1aZqy(7~mDY#Y!b;w%9jy16)XaHtLiL2;<7lg_>Y z7ex?pkjX4;(zi@#&DE_Y%TGe&6%S<$n6som-bKUcR_(+ohA+H{Ra1 zr|xgt!K;T)p8e0CkAJwnJ#qEBlN(pxx%cjS@1LIj^Xu`&o7YdT9Gv^hgO3i6KmY0X zyN91W`2O5q{yO~l(a~>@zI^TSg|A;YKHrxgUp%<^(*0Wx|33Fmb@%Y;htE9w)%N_G zznuH0I{OB1Ts!^n!o4dmfAK$n9Utvr-vIlMzkk3Mf9rq&>+0FC#p4MWu!M-L2+6!6 zfdT8E1xkPMFC}2WIt|6JL0RyJ=d%7&Htd(6KO}QCV8B|h!gXGU>#beuk<@D-rn){PNGAHg`|5r z-U4jYm|N{vfdNzcJ&uKI$3wUZ*M3rjt8mR3Dl0y)O_glkCV zYQTUg{hlt1Ype8ub!e5o((kl*d&k>5i4GkWlJ4nv3$RgRZna+p22APqI2NuQ58*0Y z`$-Y5!Zl~8tO!Z>bi4)Fs4=$^u8UT{fHm^>que8ErQfwx`buBvFD?TxV4c#Ghtdzp zTn!ko)~j$`Tw7qkIt|6JL0RyJ=d%7&HtI&@e_x~JnUz($R^)qWKiFs0w)Sh#jPgsX7vCq=jl*PNlUA|&0@@fKjC#@tG{ zE?NNt*2v$Fa*wE$e%Ds%D}ANExD3F6bxKnnN9V-CN*`E|M^zl=xr;Q#;t literal 0 HcmV?d00001 diff --git a/sources/Map/Map.cpp b/sources/Map/Map.cpp index acdaa08f..aa59f470 100644 --- a/sources/Map/Map.cpp +++ b/sources/Map/Map.cpp @@ -485,12 +485,12 @@ namespace BBM .addComponent(Vector3f(0, 0, 0)) .addComponent( WAL::Callback(), - &MapGenerator::wallCollided, Vector3f(0.25, 0.25, 0.25), Vector3f(width, 0.75, 0.75)); + &MapGenerator::wallCollided, Vector3f(0.25, 0.25, 0.25), Vector3f(width + 1, 0.75, 0.75)); scene->addEntity("FloorUp Hitbox") .addComponent(Vector3f(0, 0, height)) .addComponent( WAL::Callback(), - &MapGenerator::wallCollided, Vector3f(0.25, 0.25, 0.25),Vector3f(width, 0.75, 0.75)); + &MapGenerator::wallCollided, Vector3f(0.25, 0.25, 0.25),Vector3f(width + 1, 0.75, 0.75)); } if (floor >= 2) scene->addEntity("Middle Hitbox") From 62561162522030bcdba84ac411c5b0a7401509fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Tue, 15 Jun 2021 17:31:50 +0200 Subject: [PATCH 22/22] pr comments fixs --- sources/Runner/GameScene.cpp | 2 +- sources/Runner/ScoreScene.cpp | 72 +++++++++---------- .../EndCondition/EndConditionSystem.cpp | 11 +-- 3 files changed, 43 insertions(+), 42 deletions(-) diff --git a/sources/Runner/GameScene.cpp b/sources/Runner/GameScene.cpp index dc6caeae..c46bed30 100644 --- a/sources/Runner/GameScene.cpp +++ b/sources/Runner/GameScene.cpp @@ -37,7 +37,7 @@ namespace BBM .addComponent(8, 20, 7) .addComponent(Vector3f(8, 0, 8)); scene->addEntity("Timer") - .addComponent(std::chrono::seconds(60), [](WAL::Entity &, WAL::Wal &) { + .addComponent(std::chrono::minutes (3), [](WAL::Entity &, WAL::Wal &) { Runner::gameState.nextScene = GameState::ScoreScene; }); MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene); diff --git a/sources/Runner/ScoreScene.cpp b/sources/Runner/ScoreScene.cpp index a80f3caf..76a3008f 100644 --- a/sources/Runner/ScoreScene.cpp +++ b/sources/Runner/ScoreScene.cpp @@ -20,33 +20,33 @@ namespace BBM { std::shared_ptr Runner::loadScoreScene(WAL::Scene &gameScene) { - auto scene = std::make_shared(); - std::vector playersIconPath; - std::vector>players; + auto scene = std::make_shared(); + std::vector playersIconPath; + std::vector> players; static const std::map sounds = { {SoundComponent::JUMP, "assets/sounds/click.ogg"} }; - static const std::vector tilesColor = { - GOLD, GRAY, BROWN, PURPLE - }; - static const std::vector rankName = { - "1st", "2nd", "3rd", "4th" - }; + static const std::vector tilesColor = { + GOLD, GRAY, BROWN, PURPLE + }; + static const std::vector rankName = { + "1st", "2nd", "3rd", "4th" + }; - for (auto &[entity, score, drawable]: gameScene.view()) - players.push_back(entity); - std::sort(players.begin(), players.end(), [](WAL::Entity &entityA, WAL::Entity &entityB) { - return entityA.getComponent().aliveTime > entityB.getComponent().aliveTime; - }); + for (auto &[entity, score, drawable]: gameScene.view()) + players.push_back(entity); + std::sort(players.begin(), players.end(), [](WAL::Entity &entityA, WAL::Entity &entityB) { + return entityA.getComponent().aliveTime > entityB.getComponent().aliveTime; + }); - for (auto &entity: players) { - RAY3D::Model *model = dynamic_cast(entity.get().getComponent().drawable.get()); - std::string path = model->getTextureByMaterial(MAP_DIFFUSE).getResourcePath(); - playersIconPath.push_back(path.replace(path.find("textures"), std::string("textures").size(), "icons")); - } + for (auto &entity: players) { + RAY3D::Model *model = dynamic_cast(entity.get().getComponent().drawable.get()); + std::string path = model->getTextureByMaterial(MAP_DIFFUSE).getResourcePath(); + playersIconPath.push_back(path.replace(path.find("textures"), std::string("textures").size(), "icons")); + } - addMenuControl(*scene); - scene->addEntity("Audio ressources") + addMenuControl(*scene); + scene->addEntity("Audio ressources") .addComponent("assets/musics/music_result.ogg") .addComponent(sounds); scene->addEntity("background") @@ -55,39 +55,39 @@ namespace BBM scene->addEntity("scene title text") .addComponent(1920 / 3.25, 100, 0) .addComponent("GAME OVER", 120, RAY::Vector2(), ORANGE); - scene->addEntity("scene title text") + scene->addEntity("scene title text") .addComponent(1920 / 2.37, 250, 0) .addComponent("CONGRATS", 50, RAY::Vector2(), ORANGE); - for (int i = 0; i < players.size(); i++) { + for (int i = 0; i < players.size(); i++) { auto &playerTile = scene->addEntity("player tile") .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.5, 0) - .addComponent(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), RAY::Vector2(200, 200),tilesColor[i]); - auto &playerRank = scene->addEntity("player rank name") + .addComponent(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), + RAY::Vector2(200, 200), tilesColor[i]); + auto &playerRank = scene->addEntity("player rank name") .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.75, 0) - .addComponent(rankName[i], 30, RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), tilesColor[i]); + .addComponent(rankName[i], 30, + RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), + tilesColor[i]); auto &player = scene->addEntity("player") .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.5, 0) .addComponent(playersIconPath[i]); - } - scene->addEntity("back to main menu") + } + scene->addEntity("back to main menu") .addComponent(10, 1080 - 85, 0) .addComponent("assets/buttons/button_back.png") - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { + .addComponent([](WAL::Entity &entity, WAL::Wal &) { gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { + .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_back.png"); }) - .addComponent([](WAL::Entity &entity, WAL::Wal &) - { + .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_back_hovered.png"); }); - return scene; - } + return scene; + } } \ No newline at end of file diff --git a/sources/System/EndCondition/EndConditionSystem.cpp b/sources/System/EndCondition/EndConditionSystem.cpp index 0403d3a1..fdabe35a 100644 --- a/sources/System/EndCondition/EndConditionSystem.cpp +++ b/sources/System/EndCondition/EndConditionSystem.cpp @@ -4,7 +4,8 @@ #include "Runner/Runner.hpp" #include "Component/Score/ScoreComponent.hpp" -namespace BBM { +namespace BBM +{ EndConditionSystem::EndConditionSystem(WAL::Wal &wal) : System(wal) @@ -17,9 +18,9 @@ namespace BBM { if (!view.size()) return; - for (auto & [_ , scoreComponent, healthComponent]: view) - alivePlayersCount += (healthComponent.getHealthPoint() != 0); - if (alivePlayersCount <= 1) - Runner::gameState.nextScene = Runner::gameState.ScoreScene; + for (auto &[_, scoreComponent, healthComponent]: view) + alivePlayersCount += (healthComponent.getHealthPoint() != 0); + if (alivePlayersCount <= 1) + Runner::gameState.nextScene = Runner::gameState.ScoreScene; } } \ No newline at end of file