From 7350f78caf251100027855674cb86af71a63edc0 Mon Sep 17 00:00:00 2001 From: Oursegamin Date: Mon, 7 Jul 2025 01:23:58 +0200 Subject: [PATCH 1/5] fix: floating point exeption --- GUI/src/Renderer/Raylib/Map/MapRenderer.cpp | 18 +++++++++++++++++- GUI/src/Renderer/Raylib/Map/MapRenderer.hpp | 1 + GUI/src/Renderer/Raylib/Menu/GameMenu.cpp | 9 +++------ GUI/src/Renderer/Raylib/Model/APlayerModel.cpp | 12 +++++++++--- 4 files changed, 30 insertions(+), 10 deletions(-) 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); From 58b0661cfd9e2e6c88f7b1d9b32389f5c5abd9cb Mon Sep 17 00:00:00 2001 From: Oursegamin Date: Mon, 7 Jul 2025 01:51:48 +0200 Subject: [PATCH 2/5] fix: floating point exeption --- .../Raylib/Scene/Effect/Broadcast/WaveBroadcastEffect.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 8957f7584f50a5dc170a473c57185f53344d0157 Mon Sep 17 00:00:00 2001 From: Oursegamin Date: Tue, 8 Jul 2025 14:52:44 +0200 Subject: [PATCH 3/5] feat: teams colors --- GUI/src/Renderer/Raylib/Scene/BasicScene.cpp | 19 +++++++++++++------ GUI/src/Renderer/Raylib/Scene/BasicScene.hpp | 14 ++++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp b/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp index d50e53b..b5200e2 100644 --- a/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp +++ b/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp @@ -44,16 +44,23 @@ 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]; + } + _teamNames.push_back(player.teamName); + return _colors[_teamNames.size() - 1]; +} + 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)); diff --git a/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp b/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp index fb2040c..be6f4a7 100644 --- a/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp +++ b/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp @@ -35,6 +35,20 @@ namespace zappy { void endGame(const std::string &teamName) override; private: + Color _getColor(const game::Player &player); + + const std::vector _colors = { + WHITE, + RED, + BLUE, + GREEN, + YELLOW, + PURPLE, + ORANGE, + PINK, + BROWN, + }; + std::vector _teamNames; }; } // namespace raylib } // namespace gui From 08583d14fc7384e8c60cf44c0b991dfe94bb386f Mon Sep 17 00:00:00 2001 From: Oursegamin Date: Tue, 8 Jul 2025 14:56:56 +0200 Subject: [PATCH 4/5] fix: overflow --- GUI/src/Renderer/Raylib/Scene/BasicScene.cpp | 4 ++-- GUI/src/Renderer/Raylib/Scene/BasicScene.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp b/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp index b5200e2..ccac4cf 100644 --- a/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp +++ b/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp @@ -48,10 +48,10 @@ 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]; + return _colors[i % _colors.size()]; } _teamNames.push_back(player.teamName); - return _colors[_teamNames.size() - 1]; + return _colors[(_teamNames.size() - 1) % _colors.size()]; } void zappy::gui::raylib::BasicScene::addPlayer(const int &id) diff --git a/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp b/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp index be6f4a7..7ac20ef 100644 --- a/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp +++ b/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp @@ -39,9 +39,9 @@ namespace zappy { const std::vector _colors = { WHITE, - RED, - BLUE, GREEN, + BLUE, + RED, YELLOW, PURPLE, ORANGE, From 50360017f59e19209620c4925ef9fccce471be45 Mon Sep 17 00:00:00 2001 From: Oursegamin Date: Tue, 8 Jul 2025 15:34:57 +0200 Subject: [PATCH 5/5] feat: raylib won screen --- GUI/src/Renderer/Raylib/Scene/AScene.cpp | 26 +++++++++++++++++++- GUI/src/Renderer/Raylib/Scene/AScene.hpp | 5 ++++ GUI/src/Renderer/Raylib/Scene/BasicScene.cpp | 5 ---- GUI/src/Renderer/Raylib/Scene/BasicScene.hpp | 2 -- 4 files changed, 30 insertions(+), 8 deletions(-) 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 ccac4cf..4a02117 100644 --- a/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp +++ b/GUI/src/Renderer/Raylib/Scene/BasicScene.cpp @@ -66,8 +66,3 @@ void zappy::gui::raylib::BasicScene::addPlayer(const int &id) 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 7ac20ef..f8cbf77 100644 --- a/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp +++ b/GUI/src/Renderer/Raylib/Scene/BasicScene.hpp @@ -32,8 +32,6 @@ 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);