diff --git a/GUI/src/Renderer/Raylib/Map/MapRenderer.cpp b/GUI/src/Renderer/Raylib/Map/MapRenderer.cpp index e37f029..b693406 100644 --- a/GUI/src/Renderer/Raylib/Map/MapRenderer.cpp +++ b/GUI/src/Renderer/Raylib/Map/MapRenderer.cpp @@ -448,12 +448,28 @@ void zappy::gui::raylib::MapRenderer::removePlayer(const int &id) for (auto it = this->_players.begin(); it != this->_players.end(); it++) { if ((*it)->getId() == id) { this->_players.erase(it); - this->_playerActionQueues.erase(id); + this->removeAllActions(id); break; } } } +void zappy::gui::raylib::MapRenderer::removeAllActions(const int &id) +{ + this->_playerActionQueues.erase(id); + + this->_playerAnimAction.erase( + std::remove_if( + this->_playerAnimAction.begin(), + this->_playerAnimAction.end(), + [id](const std::shared_ptr &action) { + return action->getPlayerId() == id; + } + ), + this->_playerAnimAction.end() + ); +} + /** * @brief Supprime toutes les actions de translation pour un joueur donné. * @param id Identifiant du joueur. diff --git a/GUI/src/Renderer/Raylib/Map/MapRenderer.hpp b/GUI/src/Renderer/Raylib/Map/MapRenderer.hpp index b1a1eed..5613cbc 100644 --- a/GUI/src/Renderer/Raylib/Map/MapRenderer.hpp +++ b/GUI/src/Renderer/Raylib/Map/MapRenderer.hpp @@ -79,6 +79,7 @@ namespace zappy { void removePlayer(const int &id); void removeEgg(const int &id); + void removeAllActions(const int &id); void removeAllTranslations(const int &id); void removeAllRotations(const int &id); diff --git a/GUI/src/Renderer/Raylib/Menu/GameMenu.cpp b/GUI/src/Renderer/Raylib/Menu/GameMenu.cpp index 9365944..94cc74d 100644 --- a/GUI/src/Renderer/Raylib/Menu/GameMenu.cpp +++ b/GUI/src/Renderer/Raylib/Menu/GameMenu.cpp @@ -129,13 +129,10 @@ void zappy::gui::raylib::GameMenu::removePlayer(const int &id) } } - if (this->_displayedPlayersIndex >= static_cast(_playersIds.size())) - this->_displayedPlayersIndex = this->_displayedPlayersIndex % static_cast(_playersIds.size()); - if (this->_playersIds.empty()) { this->_displayedPlayersIndex = -1; - this->_numberPlayerDisplayed = 0; - } + } else if (this->_displayedPlayersIndex > static_cast(_playersIds.size())) + this->_displayedPlayersIndex = this->_displayedPlayersIndex % static_cast(_playersIds.size()); } std::string zappy::gui::raylib::GameMenu::_decryptBroadcast( @@ -346,7 +343,7 @@ void zappy::gui::raylib::GameMenu::_renderPlayersInfos(const int &screenWidth, c const int x = screenWidth - paddingX; const int y = paddingY; - if (this->_numberPlayerDisplayed <= 0) { + if (this->_numberPlayerDisplayed <= 0 || this->_displayedPlayersIndex < 0) { const std::string text = "There is actually no player"; const int textWidth = MeasureText(text.c_str(), textSize); DrawText(text.c_str(), x - textWidth, y, textSize, WHITE); diff --git a/GUI/src/Renderer/Raylib/Model/APlayerModel.cpp b/GUI/src/Renderer/Raylib/Model/APlayerModel.cpp index f4e9def..d2ce091 100644 --- a/GUI/src/Renderer/Raylib/Model/APlayerModel.cpp +++ b/GUI/src/Renderer/Raylib/Model/APlayerModel.cpp @@ -79,14 +79,20 @@ void zappy::gui::raylib::APlayerModel::update(const float &deltaUnits) if (this->_modelAnimations == nullptr || this->_animsCount == 0) return; - ModelAnimation anim = this->_modelAnimations[this->_animationIndexMap[this->_state]]; - float speed = (this->_animationFrameSpeedMap[this->_state]); + int currentAnimIndex = this->_animationIndexMap[this->_state]; - this->_frameAccumulator += deltaUnits * speed; + if (currentAnimIndex < 0 || currentAnimIndex >= this->_animsCount) + return; + + ModelAnimation anim = this->_modelAnimations[currentAnimIndex]; if (anim.frameCount <= 0) return; + float speed = this->_animationFrameSpeedMap[this->_state]; + + this->_frameAccumulator += deltaUnits * speed; + if (this->_frameAccumulator >= 1.0f) { const int frameAdvance = static_cast(this->_frameAccumulator); diff --git a/GUI/src/Renderer/Raylib/Scene/AScene.cpp b/GUI/src/Renderer/Raylib/Scene/AScene.cpp index 845d8bd..a85a553 100644 --- a/GUI/src/Renderer/Raylib/Scene/AScene.cpp +++ b/GUI/src/Renderer/Raylib/Scene/AScene.cpp @@ -13,7 +13,9 @@ zappy::gui::raylib::AScene::AScene(const std::shared_ptr &gameS _isMusicPlaying(true), _gameState(gameState), _skybox(), - _mapRenderer(std::make_unique(this->_gameState->getMap())) + _mapRenderer(std::make_unique(this->_gameState->getMap())), + _hasGameEnded(false), + _wonTeamName("NO TEAM NAME FOR NOW GO **** ********") {} /** @brief Initialise la scène. @@ -86,6 +88,22 @@ void zappy::gui::raylib::AScene::render() const this->_mapRenderer->render(); EndMode3D(); + + if (this->_hasGameEnded) { + constexpr int fontSize = 50; + int stringWidth = MeasureText( + TextFormat("Team \"%s\" wins!", this->_wonTeamName.c_str()), + fontSize + ); + + DrawText( + TextFormat("Team \"%s\" wins!", this->_wonTeamName.c_str()), + GetRenderWidth() / 2 - stringWidth / 2, + GetRenderHeight() / 2 - fontSize / 2, + fontSize, + GREEN + ); + } } /** @brief Ajoute un œuf à la scène. @@ -260,3 +278,9 @@ void zappy::gui::raylib::AScene::removePlayer(const int &id) { this->_mapRenderer->removePlayer(id); } + +void zappy::gui::raylib::AScene::endGame(const std::string &teamName) +{ + this->_hasGameEnded = true; + this->_wonTeamName = teamName; +} diff --git a/GUI/src/Renderer/Raylib/Scene/AScene.hpp b/GUI/src/Renderer/Raylib/Scene/AScene.hpp index 9fb8e8f..58afb73 100644 --- a/GUI/src/Renderer/Raylib/Scene/AScene.hpp +++ b/GUI/src/Renderer/Raylib/Scene/AScene.hpp @@ -56,6 +56,8 @@ namespace zappy { virtual void removeEgg(const int &id) override; virtual void removePlayer(const int &id) override; + virtual void endGame(const std::string &teamName) override; + protected: Camera _camera; @@ -66,6 +68,9 @@ namespace zappy { Skybox _skybox; const std::unique_ptr _mapRenderer; + + bool _hasGameEnded; + std::string _wonTeamName; }; } // namespace raylib } // namespace gui diff --git a/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp b/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp index d50e53b..4a02117 100644 --- a/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp +++ b/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp @@ -44,23 +44,25 @@ void zappy::gui::raylib::BasicScene::addEgg(const int &id) AScene::addEgg(id); } +Color zappy::gui::raylib::BasicScene::_getColor(const game::Player &player) +{ + for (size_t i = 0; i < _teamNames.size(); ++i) { + if (player.teamName == _teamNames[i]) + return _colors[i % _colors.size()]; + } + _teamNames.push_back(player.teamName); + return _colors[(_teamNames.size() - 1) % _colors.size()]; +} + void zappy::gui::raylib::BasicScene::addPlayer(const int &id) { auto player = std::make_unique(id); - player->setColor(Color{ - static_cast(GetRandomValue(0, 255)), - static_cast(GetRandomValue(0, 255)), - static_cast(GetRandomValue(0, 255)), - 255 - }); + game::Player gP = _gameState->getPlayerById(id); + + player->setColor(_getColor(gP)); _mapRenderer->addPlayer(std::move(player)); AScene::addPlayer(id); } - -void zappy::gui::raylib::BasicScene::endGame(const std::string &teamName) -{ - DrawText(TextFormat("Team %s wins!", teamName.c_str()), 10, 10, 20, GREEN); -} diff --git a/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp b/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp index fb2040c..f8cbf77 100644 --- a/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp +++ b/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp @@ -32,9 +32,21 @@ namespace zappy { void addEgg(const int &id) override; void addPlayer(const int &id) override; - void endGame(const std::string &teamName) override; - private: + Color _getColor(const game::Player &player); + + const std::vector _colors = { + WHITE, + GREEN, + BLUE, + RED, + YELLOW, + PURPLE, + ORANGE, + PINK, + BROWN, + }; + std::vector _teamNames; }; } // namespace raylib } // namespace gui diff --git a/GUI/src/Renderer/Raylib/Scene/Effect/Broadcast/WaveBroadcastEffect.hpp b/GUI/src/Renderer/Raylib/Scene/Effect/Broadcast/WaveBroadcastEffect.hpp index 2d51cc9..8901490 100644 --- a/GUI/src/Renderer/Raylib/Scene/Effect/Broadcast/WaveBroadcastEffect.hpp +++ b/GUI/src/Renderer/Raylib/Scene/Effect/Broadcast/WaveBroadcastEffect.hpp @@ -41,8 +41,8 @@ namespace zappy { float _pulseTimer; constexpr static float PULSE_INTERVAL = 2.0f; - constexpr static float PULSE_SPEED = 3.0f; - constexpr static float PULSE_LIFETIME = 3.0f; + constexpr static float PULSE_SPEED = 1.0f; + constexpr static float PULSE_LIFETIME = 9.0f; }; } // namespace raylib } // namespace gui