Skip to content
Open

Dev #10

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion GUI/src/Renderer/Raylib/Map/MapRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<APlayerAnimAction> &action) {
return action->getPlayerId() == id;
}
),
this->_playerAnimAction.end()
);
}

/**
* @brief Supprime toutes les actions de translation pour un joueur donné.
* @param id Identifiant du joueur.
Expand Down
1 change: 1 addition & 0 deletions GUI/src/Renderer/Raylib/Map/MapRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 3 additions & 6 deletions GUI/src/Renderer/Raylib/Menu/GameMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,10 @@ void zappy::gui::raylib::GameMenu::removePlayer(const int &id)
}
}

if (this->_displayedPlayersIndex >= static_cast<int>(_playersIds.size()))
this->_displayedPlayersIndex = this->_displayedPlayersIndex % static_cast<int>(_playersIds.size());

if (this->_playersIds.empty()) {
this->_displayedPlayersIndex = -1;
this->_numberPlayerDisplayed = 0;
}
} else if (this->_displayedPlayersIndex > static_cast<int>(_playersIds.size()))
this->_displayedPlayersIndex = this->_displayedPlayersIndex % static_cast<int>(_playersIds.size());
}

std::string zappy::gui::raylib::GameMenu::_decryptBroadcast(
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 9 additions & 3 deletions GUI/src/Renderer/Raylib/Model/APlayerModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(this->_frameAccumulator);

Expand Down
26 changes: 25 additions & 1 deletion GUI/src/Renderer/Raylib/Scene/AScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ zappy::gui::raylib::AScene::AScene(const std::shared_ptr<game::GameState> &gameS
_isMusicPlaying(true),
_gameState(gameState),
_skybox(),
_mapRenderer(std::make_unique<MapRenderer>(this->_gameState->getMap()))
_mapRenderer(std::make_unique<MapRenderer>(this->_gameState->getMap())),
_hasGameEnded(false),
_wonTeamName("NO TEAM NAME FOR NOW GO **** ********")
{}

/** @brief Initialise la scène.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
5 changes: 5 additions & 0 deletions GUI/src/Renderer/Raylib/Scene/AScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -66,6 +68,9 @@ namespace zappy {

Skybox _skybox;
const std::unique_ptr<MapRenderer> _mapRenderer;

bool _hasGameEnded;
std::string _wonTeamName;
};
} // namespace raylib
} // namespace gui
Expand Down
24 changes: 13 additions & 11 deletions GUI/src/Renderer/Raylib/Scene/BasicScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<BasicPlayerModel>(id);

player->setColor(Color{
static_cast<uint8_t>(GetRandomValue(0, 255)),
static_cast<uint8_t>(GetRandomValue(0, 255)),
static_cast<uint8_t>(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);
}
16 changes: 14 additions & 2 deletions GUI/src/Renderer/Raylib/Scene/BasicScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Color> _colors = {
WHITE,
GREEN,
BLUE,
RED,
YELLOW,
PURPLE,
ORANGE,
PINK,
BROWN,
};
std::vector<std::string> _teamNames;
};
} // namespace raylib
} // namespace gui
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down