mirror of
https://github.com/zoriya/Bomberman.git
synced 2026-06-03 10:26:29 +00:00
Adding colors to players
This commit is contained in:
@@ -6,14 +6,15 @@
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
LobbyComponent::LobbyComponent(WAL::Entity &entity, int playerID, WAL::Entity &readyButton)
|
||||
LobbyComponent::LobbyComponent(WAL::Entity &entity, int playerID, WAL::Entity &readyButton, WAL::Entity &coloredTile)
|
||||
: WAL::Component(entity),
|
||||
playerID(playerID),
|
||||
readyButton(readyButton)
|
||||
readyButton(readyButton),
|
||||
coloredTile(coloredTile)
|
||||
{}
|
||||
|
||||
WAL::Component *LobbyComponent::clone(WAL::Entity &entity) const
|
||||
{
|
||||
return new LobbyComponent(entity, this->playerID, this->readyButton);
|
||||
return new LobbyComponent(entity, this->playerID, this->readyButton, this->coloredTile);
|
||||
}
|
||||
}
|
||||
@@ -25,13 +25,15 @@ namespace BBM
|
||||
bool ready = false;
|
||||
//! @brief The entity containing the ready display.
|
||||
WAL::Entity &readyButton;
|
||||
//! @brief The colored rectangle behind the player.
|
||||
WAL::Entity &coloredTile;
|
||||
//! @brief The time of last input that this lobby player has made.
|
||||
std::chrono::time_point<std::chrono::steady_clock> lastInput;
|
||||
|
||||
Component *clone(WAL::Entity &entity) const override;
|
||||
|
||||
//! @brief Create a new lobby component.
|
||||
explicit LobbyComponent(WAL::Entity &entity, int playerID, WAL::Entity &readyButton);
|
||||
explicit LobbyComponent(WAL::Entity &entity, int playerID, WAL::Entity &readyButton, WAL::Entity &coloredTile);
|
||||
//! @brief A lobby component is copyable.
|
||||
LobbyComponent(const LobbyComponent &) = default;
|
||||
//! @brief A default destructor
|
||||
|
||||
@@ -133,18 +133,17 @@ namespace BBM
|
||||
entity.getComponent<Drawable2DComponent>().drawable->setColor(ORANGE);
|
||||
});
|
||||
|
||||
static const std::vector<RAY::Color> colors = { BLUE, RED, GREEN, YELLOW };
|
||||
for (int i = 0; i < 4; i++) {
|
||||
auto &playerTile = scene->addEntity("player tile")
|
||||
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3, 0)
|
||||
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), RAY::Vector2(200, 200), colors[i]);
|
||||
.addComponent<Drawable2DComponent, RAY2D::Rectangle>(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), RAY::Vector2(200, 200), RAY::Color(0, 0, 0, 0));
|
||||
auto &player = scene->addEntity("player")
|
||||
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>("assets/player/icons/none.png");
|
||||
auto &ready = scene->addEntity("ready")
|
||||
.addComponent<PositionComponent>(224 * (i + 1) + 200 * i, 1080 / 3, 0)
|
||||
.addComponent<Drawable2DComponent, RAY::Texture>();
|
||||
player.addComponent<LobbyComponent>(i, ready);
|
||||
player.addComponent<LobbyComponent>(i, ready, playerTile);
|
||||
}
|
||||
scene->addEntity("camera")
|
||||
.addComponent<PositionComponent>(8, 20, 7)
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace RAY3D = RAY::Drawables::Drawables3D;
|
||||
|
||||
namespace BBM
|
||||
{
|
||||
std::vector<std::string> LobbySystem::_colors = {
|
||||
std::array<std::string, 4> LobbySystem::_colors = {
|
||||
"blue",
|
||||
"red",
|
||||
"green",
|
||||
@@ -28,6 +28,15 @@ namespace BBM
|
||||
"yellow"
|
||||
};
|
||||
|
||||
std::array<RAY::Color, 4> LobbySystem::_rayColors = {
|
||||
BLUE,
|
||||
RED,
|
||||
GREEN,
|
||||
// PURPLE,
|
||||
// SKYBLUE,
|
||||
YELLOW
|
||||
};
|
||||
|
||||
LobbySystem::LobbySystem(WAL::Wal &wal)
|
||||
: System(wal)
|
||||
{}
|
||||
@@ -35,7 +44,16 @@ namespace BBM
|
||||
void LobbySystem::_nextColor(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity)
|
||||
{
|
||||
auto &lobby = entity.get<LobbyComponent>();
|
||||
if (lobby.color != -1)
|
||||
this->_colorTaken[lobby.color] = false;
|
||||
do {
|
||||
lobby.color++;
|
||||
if (lobby.color >= this->_colorTaken.size())
|
||||
lobby.color = 0;
|
||||
} while (this->_colorTaken[lobby.color]);
|
||||
this->_colorTaken[lobby.color] = true;
|
||||
entity.get<Drawable2DComponent>().drawable = std::make_shared<RAY::Texture>("assets/player/icons/" + _colors[lobby.color] + ".png");
|
||||
lobby.coloredTile.getComponent<Drawable2DComponent>().drawable->setColor(_rayColors[lobby.color]);
|
||||
}
|
||||
|
||||
void LobbySystem::onUpdate(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds dtime)
|
||||
@@ -55,21 +73,19 @@ namespace BBM
|
||||
}))
|
||||
return;
|
||||
lobby.lastInput = lastTick;
|
||||
lobby.color = 0;
|
||||
entity.get<Drawable2DComponent>().drawable = std::make_shared<RAY::Texture>("assets/player/icons/" + _colors[lobby.color] + ".png");
|
||||
|
||||
// this->_nextColor(entity);
|
||||
lobby.color = -1;
|
||||
this->_nextColor(entity);
|
||||
lobby.layout = controller.layout;
|
||||
controller.jump = false;
|
||||
return;
|
||||
}
|
||||
// if (controller.bomb)
|
||||
// this->_nextColor(entity);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto &[_, controller] : this->_wal.getScene()->view<ControllableComponent>()) {
|
||||
if (controller.layout == lobby.layout && controller.jump && !lobby.ready) {
|
||||
if (controller.layout != lobby.layout)
|
||||
continue;
|
||||
if (controller.jump && !lobby.ready) {
|
||||
lobby.ready = true;
|
||||
lobby.lastInput = lastTick;
|
||||
controller.jump = false;
|
||||
@@ -78,11 +94,13 @@ namespace BBM
|
||||
if (texture)
|
||||
texture->use("assets/player/icons/ready.png");
|
||||
}
|
||||
if (controller.bomb && !lobby.ready) {
|
||||
lobby.lastInput = lastTick;
|
||||
this->_nextColor(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void LobbySystem::onSelfUpdate()
|
||||
{
|
||||
auto &view = this->_wal.getScene()->view<TagComponent<"PlayButton">, Drawable2DComponent>();
|
||||
|
||||
@@ -20,9 +20,13 @@ namespace BBM
|
||||
//! @brief Add a controller for the player.
|
||||
static void _addController(WAL::Entity &player, ControllableComponent::Layout layout);
|
||||
|
||||
static void _nextColor(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity);
|
||||
void _nextColor(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity);
|
||||
|
||||
static std::vector<std::string> _colors;
|
||||
static std::array<std::string, 4> _colors;
|
||||
|
||||
static std::array<RAY::Color, 4> _rayColors;
|
||||
|
||||
std::array<bool, 4> _colorTaken = {};
|
||||
public:
|
||||
//! @inherit
|
||||
void onUpdate(WAL::ViewEntity<LobbyComponent, Drawable2DComponent> &entity, std::chrono::nanoseconds dtime) override;
|
||||
|
||||
Reference in New Issue
Block a user