Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/display players zappy gui #63

Merged
merged 10 commits into from
Jun 7, 2024
1 change: 0 additions & 1 deletion gui/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ TEST_FILES = Network/TestNetwork.cpp \
GameDatas/TestInventory.cpp \
GameDatas/TestPlayer.cpp \
GameDatas/TestTile.cpp \
GameDatas/TestTeam.cpp \
GameDatas/TestGameData.cpp \
Render/TestCamera.cpp \
GUIUpdater/TestGUIUpdater.cpp \
Expand Down
Binary file added gui/assets/player.glb
Binary file not shown.
5 changes: 5 additions & 0 deletions gui/include/Assets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define MODEL_SIBUR PATH_ASSETS "sibur.glb"
#define MODEL_THYSTAME PATH_ASSETS "thystame.glb"
#define MODEL_DERAUMERE PATH_ASSETS "deraumere.glb"
#define MODEL_PLAYER PATH_ASSETS "player.glb"

#define SIZE_TILE 6

Expand All @@ -27,6 +28,7 @@
#define SCALE_SIBUR (Vector3){0.2, 0.2, 0.2}
#define SCALE_THYSTAME (Vector3){0.2, 0.2, 0.2}
#define SCALE_DERAUMERE (Vector3){0.5, 0.5, 0.5}
#define SCALE_PLAYER (Vector3){0.5, 0.5, 0.5}

#define ROTATION_ANGLE_FOOD -90
#define ROTATION_ANGLE_LINEMATE -90
Expand All @@ -35,6 +37,7 @@
#define ROTATION_ANGLE_SIBUR -90
#define ROTATION_ANGLE_THYSTAME 0
#define ROTATION_ANGLE_DERAUMERE 0
#define ROTATION_ANGLE_PLAYER 0

#define ROTATION_AXIS_FOOD (Vector3){1, 0, 0}
#define ROTATION_AXIS_LINEMATE (Vector3){1, 0, 0}
Expand All @@ -43,6 +46,7 @@
#define ROTATION_AXIS_SIBUR (Vector3){1, 0, 0}
#define ROTATION_AXIS_THYSTAME (Vector3){0, 0, 0}
#define ROTATION_AXIS_DERAUMERE (Vector3){0, 0, 0}
#define ROTATION_AXIS_PLAYER (Vector3){0, 0, 0}

#define POS_FOOD (Vector3){0.5, 0.1, 1.5}
#define POS_LINEMATE (Vector3){1, 0.1, -0.5}
Expand All @@ -51,3 +55,4 @@
#define POS_SIBUR (Vector3){1.5, 0.1, -1.5}
#define POS_THYSTAME (Vector3){1, 0.2, -2}
#define POS_DERAUMERE (Vector3){2, 0.1, -2}
#define POS_PLAYER (Vector3){0, 0.1, 0}
3 changes: 2 additions & 1 deletion gui/include/GameDatas/GameData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ class Gui::GameData {
* @brief Add a team to the game.
*
* @param name Name of the team.
* @param playerModelPath Path to the asset of the team for players.
*/
void addTeam(const std::string &name);
void addTeam(const std::string &name, const std::string &playerModelPath);

/**
* @brief Add a player to a team.
Expand Down
19 changes: 12 additions & 7 deletions gui/include/GameDatas/Team.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

#include "raylib.h"
#include "GameDatas/Player.hpp"

#include <vector>
Expand All @@ -29,10 +30,9 @@ class Gui::Team {
* @brief Construct a new Team object.
*
* @param name Name of the team.
* @param playerModelPath Path to the team model asset for players.
*/
Team(const std::string &name);

// TODO: Add the necessity to set a skin for the team.
Team(const std::string &name, const std::string &playerModelPath);

/**
* @brief Destroy the Team object.
Expand Down Expand Up @@ -85,11 +85,16 @@ class Gui::Team {
*/
std::shared_ptr<Gui::Player> getPlayer(std::size_t id);

// TODO: Add a setter and a getter for the skin of the team.
/**
* @brief Get the Model object.
*
* @return Model - Model asset of the Team.
*/
Model getPlayerModel(void) const;

private:

std::string _name; // Name of the team.
std::vector<Gui::Player> _players; // Players of the team.
// TODO: Add a skin for the team using raylib.
std::string _name; // Name of the team.
std::vector<Gui::Player> _players; // Players of the team.
Model _playerModel; // Model player asset of the team.
};
6 changes: 6 additions & 0 deletions gui/include/Render/Render.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ class Gui::Render {
*/
void displayDebug(void);

/**
* @brief Display players.
*
*/
void displayPlayers(void) const;

/**
* @brief Display the map.
*
Expand Down
5 changes: 3 additions & 2 deletions gui/src/GUIUpdater/GUIUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
** GUIUpdater
*/

#include "GUIUpdater/GUIUpdater.hpp"
#include "Assets.hpp"
#include "Error/Error.hpp"
#include "GUIUpdater/GUIUpdater.hpp"

Gui::GUIUpdater::GUIUpdater(std::shared_ptr<GameData> gameData) : _gameData(gameData) {}

Expand Down Expand Up @@ -69,7 +70,7 @@ void Gui::GUIUpdater::updateTeamNames(const std::vector<std::string> &data)
{
try {
for (size_t i = 0; i < data.size(); i++)
_gameData->addTeam(data[i]);
_gameData->addTeam(data[i], MODEL_PLAYER);
} catch (const std::exception &error) {
throw Gui::Errors::GuiUpdaterException("Invalid team names");
}
Expand Down
4 changes: 2 additions & 2 deletions gui/src/GameDatas/GameData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ void Gui::GameData::addTeam(const Gui::Team &team)
_teams.push_back(team);
}

void Gui::GameData::addTeam(const std::string &name)
void Gui::GameData::addTeam(const std::string &name, const std::string &playerModelPath)
{
for (auto &team : _teams) {
if (team.getName() == name)
throw Gui::Errors::GuiGameDataException("Team already exists");
}
_teams.push_back(Gui::Team(name));
_teams.push_back(Gui::Team(name, playerModelPath));
}

void Gui::GameData::addPlayerToTeam(const std::string &teamName, const Gui::Player &player)
Expand Down
10 changes: 9 additions & 1 deletion gui/src/GameDatas/Team.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

#include "GameDatas/Team.hpp"

Gui::Team::Team(const std::string &name) : _name(name) {}
Gui::Team::Team(const std::string &name, const std::string &playerModelPath) : _name(name)
{
_playerModel = LoadModel(playerModelPath.c_str());
}

const std::string &Gui::Team::getName() const
{
Expand Down Expand Up @@ -49,3 +52,8 @@ std::shared_ptr<Gui::Player> Gui::Team::getPlayer(std::size_t id)
}
return nullptr;
}

Model Gui::Team::getPlayerModel(void) const
{
return _playerModel;
}
12 changes: 12 additions & 0 deletions gui/src/Render/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ void Gui::Render::draw()

BeginMode3D(*_camera.getCamera());
displayMap();
displayPlayers();
EndMode3D();

displayDebug();
Expand Down Expand Up @@ -90,6 +91,17 @@ void Gui::Render::displayDebug(void)
}
}

void Gui::Render::displayPlayers(void) const
{
for (auto &team : _gameData->getTeams()) {
for (auto &player : team.getPlayers()) {
Vector3 posPlayer = (Vector3){(float)(player.getPosition().first), 0, (float)(player.getPosition().second)};
Vector3 posAssetPlayer = POS_PLAYER;
DrawModelEx(team.getPlayerModel(), (Vector3){posPlayer.x + posAssetPlayer.x, posPlayer.y + posAssetPlayer.y, posPlayer.z + posAssetPlayer.z}, ROTATION_AXIS_PLAYER, ROTATION_ANGLE_PLAYER, SCALE_PLAYER, WHITE);
}
}
}

void Gui::Render::displayMap(void) const
{
for (auto &line : _gameData->getMap()) {
Expand Down
Loading