Skip to content

Commit

Permalink
Merge pull request #53 from FppEpitech/feat/display-tile-of-map-zappy…
Browse files Browse the repository at this point in the history
…-gui

Feat/display tile of map zappy gui
  • Loading branch information
mathieurobert1 authored Jun 5, 2024
2 parents 6dab0d2 + 216892b commit c8db126
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 7 deletions.
Binary file added gui/assets/building_platform.glb
Binary file not shown.
11 changes: 11 additions & 0 deletions gui/include/Assets.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
** EPITECH PROJECT, 2024
** Zappy GUI
** File description:
** Assets
*/

#pragma once

#define MODEL_TILE "assets/building_platform.glb"
#define SIZE_TILE 6
11 changes: 10 additions & 1 deletion gui/include/GameDatas/Tile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once

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

namespace Gui {
Expand Down Expand Up @@ -49,6 +50,13 @@ class Gui::Tile {
*/
std::pair<std::size_t, std::size_t> getPosition(void) const;

/**
* @brief Get the Position In Space object.
*
* @return Vector3 - Position in space.
*/
Vector3 getPositionIn3DSpace(void);

/**
* @brief Inventory of the tile.
*
Expand All @@ -57,5 +65,6 @@ class Gui::Tile {

private:

std::pair<std::size_t, std::size_t> _position; // Position x y.
std::pair<std::size_t, std::size_t> _position; // Position x y.
Vector3 _positionIn3DSpace; // Position in 3D space.
};
24 changes: 19 additions & 5 deletions gui/include/Render/Render.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,29 @@ class Gui::Render {
*/
bool getIsDebug(void);

private:

UserCamera _camera; // Camera of the scene.
bool _isDebug; // Display or not the debug informations.
std::shared_ptr<GameData> _gameData; // GameData class to store the game's data.

Model _tileModel; // Model to display for tiles.

/**
* @brief Load the models to draw.
*
*/
void LoadModels(void);

/**
* @brief Display the debug interface.
*
*/
void displayDebug(void);

private:

UserCamera _camera; // Camera of the scene.
bool _isDebug; // Display or not the debug informations.
std::shared_ptr<GameData> _gameData; // GameData class to store the game's data.
/**
* @brief Display the map.
*
*/
void displayMap();
};
9 changes: 8 additions & 1 deletion gui/src/GameDatas/Tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@
** Tile
*/

#include "Assets.hpp"
#include "GameDatas/Tile.hpp"

Gui::Tile::Tile(std::pair<std::size_t, std::size_t> position)
{
_position = position;
setPosition(position);
}

void Gui::Tile::setPosition(std::pair<std::size_t, std::size_t> position)
{
_position = position;
_positionIn3DSpace = (Vector3) {(float)(position.first * SIZE_TILE), 0.0f, (float)(position.second * SIZE_TILE)};
}

std::pair<std::size_t, std::size_t> Gui::Tile::getPosition(void) const
{
return _position;
}

Vector3 Gui::Tile::getPositionIn3DSpace(void)
{
return _positionIn3DSpace;
}
16 changes: 16 additions & 0 deletions gui/src/Render/Render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
** Render
*/

#include "Assets.hpp"
#include "Render/Render.hpp"

#include <string>
Expand All @@ -16,6 +17,12 @@ Gui::Render::Render(std::shared_ptr<GameData> gameData)
DisableCursor();
SetTargetFPS(140);
_isDebug = false;
this->LoadModels();
}

void Gui::Render::LoadModels(void)
{
_tileModel = LoadModel(MODEL_TILE);
}

Gui::Render::~Render()
Expand All @@ -37,6 +44,7 @@ void Gui::Render::draw()

BeginMode3D(*_camera.getCamera());
DrawGrid(20, 1.0f);
displayMap();
EndMode3D();

displayDebug();
Expand Down Expand Up @@ -75,3 +83,11 @@ void Gui::Render::displayDebug(void)
).c_str(), 10, 50, 20, LIME);
}
}

void Gui::Render::displayMap()
{
for (auto &line : _gameData->getMap()) {
for (auto &tile : line)
DrawModel(_tileModel, tile.getPositionIn3DSpace(), 0.001f, WHITE);
}
}

0 comments on commit c8db126

Please sign in to comment.