From 41d8369ba53338068cd540a23fb3a20e116d53a2 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 09:45:57 +0200 Subject: [PATCH 1/9] 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 2/9] 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 377a07cd371bb0d18096c6a16317b7894490bb60 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 10:30:58 +0200 Subject: [PATCH 3/9] 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 0bc65f2ffdba2c8ab8f7650db45fbe30d6503403 Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 10:42:56 +0200 Subject: [PATCH 4/9] 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 5/9] 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 6/9] 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 7/9] 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 8/9] 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 a0784875d36a48e8733a1010e930f60523b5888b Mon Sep 17 00:00:00 2001 From: "arthur.jamet" Date: Tue, 15 Jun 2021 12:31:44 +0200 Subject: [PATCH 9/9] 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)