diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c87fc07..ad089dce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,12 @@ set(SOURCES sources/Runner/ScoreScene.cpp sources/System/Timer/TimerUISystem.hpp sources/System/Timer/TimerUISystem.cpp + sources/System/Bonus/BonusUISystem.hpp + sources/System/Bonus/BonusUISystem.cpp + sources/Component/Color/ColorComponent.hpp + sources/Component/Color/ColorComponent.cpp + sources/Component/Stat/StatComponent.cpp + sources/Component/Stat/StatComponent.hpp ) add_executable(bomberman sources/main.cpp diff --git a/sources/Component/Color/ColorComponent.cpp b/sources/Component/Color/ColorComponent.cpp new file mode 100644 index 00000000..994f7f10 --- /dev/null +++ b/sources/Component/Color/ColorComponent.cpp @@ -0,0 +1,24 @@ +// +// +// + +#include "ColorComponent.hpp" + +namespace BBM +{ + + ColorComponent::ColorComponent(WAL::Entity &entity, RAY::Color color) + : Component(entity), + color(color) + {} + + ColorComponent::ColorComponent(WAL::Entity &entity, unsigned char r, unsigned char g, unsigned char b, unsigned char a) + : Component(entity), + color(r, g, b, a) + {} + + WAL::Component *ColorComponent::clone(WAL::Entity &entity) const + { + return new ColorComponent(entity, this->color); + } +} // namespace WAL \ No newline at end of file diff --git a/sources/Component/Color/ColorComponent.hpp b/sources/Component/Color/ColorComponent.hpp new file mode 100644 index 00000000..d75b5818 --- /dev/null +++ b/sources/Component/Color/ColorComponent.hpp @@ -0,0 +1,33 @@ +// +// +// + +#pragma once + +#include "Color.hpp" +#include "Component/Component.hpp" + +namespace BBM +{ + //! @brief A basic color component + class ColorComponent : public WAL::Component + { + public: + //! @brief Get the editable color of this entity + RAY::Color color; + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief Create a new ColorComponent at a certain color + ColorComponent(WAL::Entity &entity, RAY::Color color); + //! @brief Create a new ColorComponent at a certain color + ColorComponent(WAL::Entity &entity, unsigned char r, unsigned char g, unsigned char b, unsigned char a); + //! @brief A color component is copy constructable + ColorComponent(const ColorComponent &) = default; + //! @brief A default destructor + ~ColorComponent() override = default; + //! @brief A color component is not assignable + ColorComponent &operator=(const ColorComponent &) = delete; + }; +} // namespace WAL \ No newline at end of file diff --git a/sources/Component/Stat/StatComponent.cpp b/sources/Component/Stat/StatComponent.cpp new file mode 100644 index 00000000..2e20f6f6 --- /dev/null +++ b/sources/Component/Stat/StatComponent.cpp @@ -0,0 +1,19 @@ +// +// +// + +#include "StatComponent.hpp" + +namespace BBM +{ + + StatComponent::StatComponent(WAL::Entity &entity, WAL::Callback callback) + : Component(entity), + updater(callback) + {} + + WAL::Component *StatComponent::clone(WAL::Entity &entity) const + { + return new StatComponent(entity, this->updater); + } +} // namespace WAL \ No newline at end of file diff --git a/sources/Component/Stat/StatComponent.hpp b/sources/Component/Stat/StatComponent.hpp new file mode 100644 index 00000000..75f9733f --- /dev/null +++ b/sources/Component/Stat/StatComponent.hpp @@ -0,0 +1,33 @@ +// +// +// + +#pragma once + +#include "Component/Component.hpp" +#include "Models/Callback.hpp" +#include "Wal.hpp" +#include "Component/Renderer/Drawable2DComponent.hpp" + +namespace BBM +{ + //! @brief A Stat component which contains a text and a callback + class StatComponent : public WAL::Component + { + public: + //! @brief onEvent callback + WAL::Callback updater; + + //! @inherit + WAL::Component *clone(WAL::Entity &entity) const override; + + //! @brief Create a new StatComponent with a callback + StatComponent(WAL::Entity &entity, WAL::Callback callback); + //! @brief A color component is copy constructable + StatComponent(const StatComponent &) = default; + //! @brief A default destructor + ~StatComponent() override = default; + //! @brief A color component is not assignable + StatComponent &operator=(const StatComponent &) = delete; + }; +} // namespace WAL \ No newline at end of file diff --git a/sources/Runner/Runner.cpp b/sources/Runner/Runner.cpp index 4f48de05..f191dd68 100644 --- a/sources/Runner/Runner.cpp +++ b/sources/Runner/Runner.cpp @@ -38,6 +38,7 @@ #include "System/Score/ScoreSystem.hpp" #include "System/EndCondition/EndConditionSystem.hpp" #include "Component/Lobby/LobbyComponent.hpp" +#include "System/Bonus/BonusUISystem.hpp" namespace BBM { @@ -77,6 +78,7 @@ namespace BBM .addSystem() .addSystem() .addSystem() + .addSystem() .addSystem() .addSystem() .addSystem() diff --git a/sources/System/Bonus/BonusUISystem.cpp b/sources/System/Bonus/BonusUISystem.cpp new file mode 100644 index 00000000..d6ac5598 --- /dev/null +++ b/sources/System/Bonus/BonusUISystem.cpp @@ -0,0 +1,17 @@ +// +// Created by hbenjamin on 09/06/2021. +// + +#include "BonusUISystem.hpp" + +namespace BBM +{ + BonusUISystem::BonusUISystem(WAL::Wal &wal) + : System(wal) + {} + + void BonusUISystem::onFixedUpdate(WAL::ViewEntity &entity) + { + entity.get().updater(entity.get()); + } +} \ No newline at end of file diff --git a/sources/System/Bonus/BonusUISystem.hpp b/sources/System/Bonus/BonusUISystem.hpp new file mode 100644 index 00000000..ddc6f95f --- /dev/null +++ b/sources/System/Bonus/BonusUISystem.hpp @@ -0,0 +1,32 @@ +// +// +// + +#pragma once + +#include "System/System.hpp" +#include "Wal.hpp" +#include "Component/Renderer/Drawable2DComponent.hpp" +#include "Component/Stat/StatComponent.hpp" + +namespace BBM +{ + //! @brief The system that allow the text of the ui to display current values + class BonusUISystem : public WAL::System + { + private: + public: + //! @inherit + void onFixedUpdate(WAL::ViewEntity &entity) override; + + //! @brief A default constructor + explicit BonusUISystem(WAL::Wal &wal); + //! @brief A bomb holder system is copy constructable + BonusUISystem(const BonusUISystem &) = default; + //! @brief A default destructor + ~BonusUISystem() override = default; + //! @brief A bomb holder system is not assignable. + BonusUISystem &operator=(const BonusUISystem &) = delete; + }; +} + diff --git a/sources/System/Lobby/LobbySystem.cpp b/sources/System/Lobby/LobbySystem.cpp index 6dbc945e..15ec6505 100644 --- a/sources/System/Lobby/LobbySystem.cpp +++ b/sources/System/Lobby/LobbySystem.cpp @@ -14,7 +14,12 @@ #include #include #include -#include +#include +#include +#include "Component/Color/ColorComponent.hpp" +#include "Component/Stat/StatComponent.hpp" +#include "Component/Bonus/PlayerBonusComponent.hpp" +#include "Component/BombHolder/BombHolderComponent.hpp" namespace RAY3D = RAY::Drawables::Drawables3D; namespace RAY2D = RAY::Drawables::Drawables2D; @@ -179,17 +184,57 @@ namespace BBM .addComponent(x, y, 0) .addComponent(texturePath); scene->addEntity("player hide fireup") - .addComponent(x + 172, y + 35, 0) - .addComponent(x, y, 35, 35, _rayColors[lobby.color]); + .addComponent(x + 220, y + 35, 0) + .addComponent("", x, y, 50, WHITE) + .addComponent([player](Drawable2DComponent &drawble) { + const BombHolderComponent *bonus = player.tryGetComponent(); + + if (!bonus) + return; + RAY2D::Text *text = dynamic_cast(drawble.drawable.get()); + if (!text) + return; + text->setText(std::to_string(bonus->explosionRadius)); + }); scene->addEntity("player hide bombup") - .addComponent(x + 172, y + 77, 0) - .addComponent(x, y, 35, 35, _rayColors[lobby.color]); + .addComponent(x + 220, y + 77, 0) + .addComponent("", x, y, 50, WHITE) + .addComponent([player](Drawable2DComponent &drawble) { + const BombHolderComponent *bonus = player.tryGetComponent(); + + if (!bonus) + return; + RAY2D::Text *text = dynamic_cast(drawble.drawable.get()); + if (!text) + return; + text->setText(std::to_string(bonus->maxBombCount)); + }); scene->addEntity("player hide speedup") - .addComponent(x + 172, y + 122, 0) - .addComponent(x, y, 35, 35, _rayColors[lobby.color]); - scene->addEntity("player hide speedup") - .addComponent(x + 172, y + 161, 0) - .addComponent(x, y, 35, 35, _rayColors[lobby.color]); + .addComponent(x + 220, y + 122, 0) + .addComponent("", x, y, 50, WHITE) + .addComponent([player](Drawable2DComponent &drawble) { + const ControllableComponent *bonus = player.tryGetComponent(); + + if (!bonus) + return; + RAY2D::Text *text = dynamic_cast(drawble.drawable.get()); + if (!text) + return; + text->setText(std::to_string(bonus->speed)); + }); + scene->addEntity("player hide wall") + .addComponent(x + 220, y + 161, 0) + .addComponent("", x, y, 50, WHITE) + .addComponent([player](Drawable2DComponent &drawble) { + const PlayerBonusComponent *bonus = player.tryGetComponent(); + + if (!bonus) + return; + RAY2D::Text *text = dynamic_cast(drawble.drawable.get()); + if (!text) + return; + text->setText(bonus->isNoClipOn ? "YES" : "NO"); + }); playerCount++; } Runner::gameState._loadedScenes[GameState::SceneID::GameScene] = scene;