diff --git a/sources/Component/Lobby/LobbyComponent.cpp b/sources/Component/Lobby/LobbyComponent.cpp index 9f46bfb4..a945f112 100644 --- a/sources/Component/Lobby/LobbyComponent.cpp +++ b/sources/Component/Lobby/LobbyComponent.cpp @@ -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); } } \ No newline at end of file diff --git a/sources/Component/Lobby/LobbyComponent.hpp b/sources/Component/Lobby/LobbyComponent.hpp index 18647649..4061d1ce 100644 --- a/sources/Component/Lobby/LobbyComponent.hpp +++ b/sources/Component/Lobby/LobbyComponent.hpp @@ -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 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 diff --git a/sources/Runner/LobbyScene.cpp b/sources/Runner/LobbyScene.cpp index a133a35f..54e45191 100644 --- a/sources/Runner/LobbyScene.cpp +++ b/sources/Runner/LobbyScene.cpp @@ -133,18 +133,17 @@ namespace BBM entity.getComponent().drawable->setColor(ORANGE); }); - static const std::vector colors = { BLUE, RED, GREEN, YELLOW }; for (int i = 0; i < 4; i++) { auto &playerTile = scene->addEntity("player tile") .addComponent(224 * (i + 1) + 200 * i, 1080 / 3, 0) - .addComponent(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), RAY::Vector2(200, 200), colors[i]); + .addComponent(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(224 * (i + 1) + 200 * i, 1080 / 3, 0) .addComponent("assets/player/icons/none.png"); auto &ready = scene->addEntity("ready") .addComponent(224 * (i + 1) + 200 * i, 1080 / 3, 0) .addComponent(); - player.addComponent(i, ready); + player.addComponent(i, ready, playerTile); } scene->addEntity("camera") .addComponent(8, 20, 7) diff --git a/sources/System/Lobby/LobbySystem.cpp b/sources/System/Lobby/LobbySystem.cpp index 8c12ce79..3f9df0c7 100644 --- a/sources/System/Lobby/LobbySystem.cpp +++ b/sources/System/Lobby/LobbySystem.cpp @@ -19,7 +19,7 @@ namespace RAY3D = RAY::Drawables::Drawables3D; namespace BBM { - std::vector LobbySystem::_colors = { + std::array LobbySystem::_colors = { "blue", "red", "green", @@ -28,6 +28,15 @@ namespace BBM "yellow" }; + std::array 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 &entity) { auto &lobby = entity.get(); + 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().drawable = std::make_shared("assets/player/icons/" + _colors[lobby.color] + ".png"); + lobby.coloredTile.getComponent().drawable->setColor(_rayColors[lobby.color]); } void LobbySystem::onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) @@ -55,21 +73,19 @@ namespace BBM })) return; lobby.lastInput = lastTick; - lobby.color = 0; - entity.get().drawable = std::make_shared("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()) { - 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, Drawable2DComponent>(); diff --git a/sources/System/Lobby/LobbySystem.hpp b/sources/System/Lobby/LobbySystem.hpp index b1b3a495..b1eb7d8c 100644 --- a/sources/System/Lobby/LobbySystem.hpp +++ b/sources/System/Lobby/LobbySystem.hpp @@ -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 &entity); + void _nextColor(WAL::ViewEntity &entity); - static std::vector _colors; + static std::array _colors; + + static std::array _rayColors; + + std::array _colorTaken = {}; public: //! @inherit void onUpdate(WAL::ViewEntity &entity, std::chrono::nanoseconds dtime) override;