mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-05-26 07:49:33 +00:00
display simpe stat, no update
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -0,0 +1,19 @@
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include "StatComponent.hpp"
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
|
||||
StatComponent::StatComponent(WAL::Entity &entity, WAL::Callback<Drawable2DComponent &> callback)
|
||||
: Component(entity),
|
||||
updater(callback)
|
||||
{}
|
||||
|
||||
WAL::Component *StatComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new StatComponent(entity, this->updater);
|
||||
}
|
||||
} // namespace WAL
|
||||
@@ -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<Drawable2DComponent &> updater;
|
||||
|
||||
//! @inherit
|
||||
WAL::Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief Create a new StatComponent with a callback
|
||||
StatComponent(WAL::Entity &entity, WAL::Callback<Drawable2DComponent &> 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
|
||||
@@ -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<BombHolderSystem>()
|
||||
.addSystem<EventSystem>()
|
||||
.addSystem<HealthSystem>()
|
||||
.addSystem<BonusUISystem>()
|
||||
.addSystem<CollisionSystem>()
|
||||
.addSystem<LevitateSystem>()
|
||||
.addSystem<PlayerBonusSystem>()
|
||||
|
||||
@@ -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<StatComponent, Drawable2DComponent> &entity)
|
||||
{
|
||||
entity.get<StatComponent>().updater(entity.get<Drawable2DComponent>());
|
||||
}
|
||||
}
|
||||
@@ -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<StatComponent, Drawable2DComponent>
|
||||
{
|
||||
private:
|
||||
public:
|
||||
//! @inherit
|
||||
void onFixedUpdate(WAL::ViewEntity<StatComponent, Drawable2DComponent> &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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -14,7 +14,12 @@
|
||||
#include <Component/Gamepad/GamepadComponent.hpp>
|
||||
#include <Component/Position/PositionComponent.hpp>
|
||||
#include <Component/Renderer/Drawable3DComponent.hpp>
|
||||
#include <Drawables/2D/Rectangle.hpp>
|
||||
#include <Drawables/2D/Text.hpp>
|
||||
#include <Drawables/2D/Text.hpp>
|
||||
#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<PositionComponent>(x, y, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>(texturePath);
|
||||
scene->addEntity("player hide fireup")
|
||||
.addComponent<PositionComponent>(x + 172, y + 35, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(x, y, 35, 35, _rayColors[lobby.color]);
|
||||
.addComponent<PositionComponent>(x + 220, y + 35, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("", x, y, 50, WHITE)
|
||||
.addComponent<StatComponent>([player](Drawable2DComponent &drawble) {
|
||||
const BombHolderComponent *bonus = player.tryGetComponent<BombHolderComponent>();
|
||||
|
||||
if (!bonus)
|
||||
return;
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(drawble.drawable.get());
|
||||
if (!text)
|
||||
return;
|
||||
text->setText(std::to_string(bonus->explosionRadius));
|
||||
});
|
||||
scene->addEntity("player hide bombup")
|
||||
.addComponent<PositionComponent>(x + 172, y + 77, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(x, y, 35, 35, _rayColors[lobby.color]);
|
||||
.addComponent<PositionComponent>(x + 220, y + 77, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("", x, y, 50, WHITE)
|
||||
.addComponent<StatComponent>([player](Drawable2DComponent &drawble) {
|
||||
const BombHolderComponent *bonus = player.tryGetComponent<BombHolderComponent>();
|
||||
|
||||
if (!bonus)
|
||||
return;
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(drawble.drawable.get());
|
||||
if (!text)
|
||||
return;
|
||||
text->setText(std::to_string(bonus->maxBombCount));
|
||||
});
|
||||
scene->addEntity("player hide speedup")
|
||||
.addComponent<PositionComponent>(x + 172, y + 122, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(x, y, 35, 35, _rayColors[lobby.color]);
|
||||
scene->addEntity("player hide speedup")
|
||||
.addComponent<PositionComponent>(x + 172, y + 161, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(x, y, 35, 35, _rayColors[lobby.color]);
|
||||
.addComponent<PositionComponent>(x + 220, y + 122, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("", x, y, 50, WHITE)
|
||||
.addComponent<StatComponent>([player](Drawable2DComponent &drawble) {
|
||||
const ControllableComponent *bonus = player.tryGetComponent<ControllableComponent>();
|
||||
|
||||
if (!bonus)
|
||||
return;
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(drawble.drawable.get());
|
||||
if (!text)
|
||||
return;
|
||||
text->setText(std::to_string(bonus->speed));
|
||||
});
|
||||
scene->addEntity("player hide wall")
|
||||
.addComponent<PositionComponent>(x + 220, y + 161, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Text>("", x, y, 50, WHITE)
|
||||
.addComponent<StatComponent>([player](Drawable2DComponent &drawble) {
|
||||
const PlayerBonusComponent *bonus = player.tryGetComponent<PlayerBonusComponent>();
|
||||
|
||||
if (!bonus)
|
||||
return;
|
||||
RAY2D::Text *text = dynamic_cast<RAY2D::Text *>(drawble.drawable.get());
|
||||
if (!text)
|
||||
return;
|
||||
text->setText(bonus->isNoClipOn ? "YES" : "NO");
|
||||
});
|
||||
playerCount++;
|
||||
}
|
||||
Runner::gameState._loadedScenes[GameState::SceneID::GameScene] = scene;
|
||||
|
||||
Reference in New Issue
Block a user