Add more useless commentary
This commit is contained in:
parent
7f5984b229
commit
a206123854
|
@ -34,6 +34,7 @@ class ChannelManager {
|
|||
return it != channels.end() ? it->second : false;
|
||||
}
|
||||
|
||||
// Verify if all given channels are in corresponding state
|
||||
bool areChannelsInState(const unordered_map<int, bool> &states)
|
||||
{
|
||||
for(const auto &state : states)
|
||||
|
|
22
Game.cpp
22
Game.cpp
|
@ -34,6 +34,7 @@ Manager Game::entityManager;
|
|||
|
||||
Entity &player(Game::entityManager.addEntity());
|
||||
|
||||
// Game constructor
|
||||
Game::~Game()
|
||||
{
|
||||
if(renderer != NULL) SDL_DestroyRenderer(renderer);
|
||||
|
@ -44,8 +45,10 @@ Game::~Game()
|
|||
cerr << "Game cleaned.\n";
|
||||
}
|
||||
|
||||
// Init SDL, IMG...
|
||||
bool Game::Init()
|
||||
{
|
||||
// Init SDL
|
||||
if(SDL_Init(SDL_INIT_EVERYTHING) != 0)
|
||||
{
|
||||
cerr << "Erreur SDL_Init : " << SDL_GetError() << '\n';
|
||||
|
@ -53,6 +56,7 @@ bool Game::Init()
|
|||
}
|
||||
cerr << "SDL initialised successfully.\n";
|
||||
|
||||
// Init IMG
|
||||
if(IMG_Init(IMG_INIT_PNG) == 0)
|
||||
{
|
||||
cerr << "Erreur IMG_Init : " << IMG_GetError() << '\n';
|
||||
|
@ -60,6 +64,7 @@ bool Game::Init()
|
|||
}
|
||||
cerr << "IMG initialised successfully.\n";
|
||||
|
||||
// Create Window
|
||||
m_window = SDL_CreateWindow(WINDOW_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WINDOW_WIDTH, WINDOW_HEIGHT, SDL_WINDOW_SHOWN);
|
||||
if(m_window == NULL)
|
||||
{
|
||||
|
@ -68,8 +73,9 @@ bool Game::Init()
|
|||
}
|
||||
cerr << "Window created successfully.\n";
|
||||
|
||||
// Disable unused events
|
||||
SDL_EventType disableEvents[] = {
|
||||
// Événements liés aux manettes (joysticks)
|
||||
// Joysticks events
|
||||
SDL_JOYAXISMOTION,
|
||||
SDL_JOYBALLMOTION,
|
||||
SDL_JOYHATMOTION,
|
||||
|
@ -78,7 +84,7 @@ bool Game::Init()
|
|||
SDL_JOYDEVICEADDED,
|
||||
SDL_JOYDEVICEREMOVED,
|
||||
|
||||
// Événements liés aux contrôleurs (game controllers)
|
||||
// Game controllers events
|
||||
SDL_CONTROLLERAXISMOTION,
|
||||
SDL_CONTROLLERBUTTONDOWN,
|
||||
SDL_CONTROLLERBUTTONUP,
|
||||
|
@ -86,13 +92,13 @@ bool Game::Init()
|
|||
SDL_CONTROLLERDEVICEREMOVED,
|
||||
SDL_CONTROLLERDEVICEREMAPPED,
|
||||
|
||||
// Événements de glisser-déposer (drag & drop)
|
||||
// Drag & drop events
|
||||
SDL_DROPFILE,
|
||||
SDL_DROPTEXT,
|
||||
SDL_DROPBEGIN,
|
||||
SDL_DROPCOMPLETE,
|
||||
|
||||
// Événements liés aux appareils tactiles
|
||||
// Tactile events
|
||||
SDL_FINGERMOTION,
|
||||
SDL_FINGERDOWN,
|
||||
SDL_FINGERUP,
|
||||
|
@ -100,15 +106,15 @@ bool Game::Init()
|
|||
SDL_DOLLARGESTURE,
|
||||
SDL_DOLLARRECORD,
|
||||
|
||||
// Événements liés aux capteurs
|
||||
// Sensor event
|
||||
SDL_SENSORUPDATE,
|
||||
|
||||
// Événements utilisateurs (custom)
|
||||
// User event
|
||||
SDL_USEREVENT
|
||||
};
|
||||
|
||||
for(const SDL_EventType &disableEvent : disableEvents) SDL_EventState(disableEvent, SDL_DISABLE);
|
||||
|
||||
// Create renderer
|
||||
renderer = SDL_CreateRenderer(m_window, -1, 0);
|
||||
if(renderer == NULL)
|
||||
{
|
||||
|
@ -117,8 +123,8 @@ bool Game::Init()
|
|||
}
|
||||
cerr << "Renderer created successfully\n\n";
|
||||
|
||||
// Load initial map and tileset
|
||||
tileMap.LoadTileset("ressources/tileset/tileset.png");
|
||||
|
||||
tileMap.LoadTileMap("ressources/maps/dungeon entry.json");
|
||||
|
||||
TransformComponent *p_transform = &player.addComponent<TransformComponent>(tileMap.getPlayerInitPos(), Vector2D<int>(32, 32), 2, 3);
|
||||
|
|
15
TileMap.cpp
15
TileMap.cpp
|
@ -23,18 +23,21 @@
|
|||
using std::string, std::exception, std::vector, std::cerr, std::runtime_error;
|
||||
using json = nlohmann::json;
|
||||
|
||||
// Load a map from memory
|
||||
void TileMap::LoadTileMap(const string &path)
|
||||
{
|
||||
// Load the map data from memory
|
||||
json *mapData;
|
||||
|
||||
mapData = Game::mapManager.LoadMap(path);
|
||||
|
||||
// Get tilemap width and height same for world
|
||||
tileMapWidth = mapData->at("TileMapWidth").get<int>();
|
||||
tileMapHeight = mapData->at("TileMapHeight").get<int>();
|
||||
|
||||
worldWidth = tileMapWidth * TILE_SIZE * TILEMAP_SCALE;
|
||||
worldHeight = tileMapHeight * TILE_SIZE * TILEMAP_SCALE;
|
||||
|
||||
// Clear layers and hitboxes and resize them
|
||||
m_tilesLayer1.clear();
|
||||
m_tilesLayer2.clear();
|
||||
m_tilesLayer3.clear();
|
||||
|
@ -47,6 +50,7 @@ void TileMap::LoadTileMap(const string &path)
|
|||
|
||||
hitboxes.resize(tileMapWidth * tileMapHeight);
|
||||
|
||||
// Load layers and hitboxes from map data
|
||||
string layers[] {"Layer 1","Layer 2","Layer 3", "Hitboxes"};
|
||||
|
||||
for(const string &layer : layers)
|
||||
|
@ -84,7 +88,6 @@ void TileMap::LoadTileMap(const string &path)
|
|||
}
|
||||
|
||||
m_nextMaps.clear();
|
||||
|
||||
for(auto it {mapData->at("NextMaps").begin()}; it < mapData->at("NextMaps").end(); it++)
|
||||
{
|
||||
NextMap nextMap;
|
||||
|
@ -95,6 +98,7 @@ void TileMap::LoadTileMap(const string &path)
|
|||
m_nextMaps.emplace(it->at("Number").get<int>(), nextMap);
|
||||
}
|
||||
|
||||
// Erase lasts entities and load news if there are some
|
||||
std::size_t numberOfEntity {Game::entityManager.getNumberOfEntity()};
|
||||
|
||||
for(std::size_t i {1}; i < numberOfEntity; i++) Game::entityManager.erase(i);
|
||||
|
@ -157,6 +161,7 @@ void TileMap::LoadTileMap(const string &path)
|
|||
}
|
||||
}
|
||||
|
||||
// Texture renderer creating
|
||||
Game::textureRenderer = SDL_CreateTexture(Game::renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, worldWidth, worldHeight);
|
||||
if(Game::textureRenderer == NULL)
|
||||
{
|
||||
|
@ -165,6 +170,7 @@ void TileMap::LoadTileMap(const string &path)
|
|||
}
|
||||
}
|
||||
|
||||
// Load the corresponding next map from memory
|
||||
void TileMap::LoadNextMap(int nextMapNumber)
|
||||
{
|
||||
NextMap nextMap = m_nextMaps.at(nextMapNumber);
|
||||
|
@ -174,6 +180,7 @@ void TileMap::LoadNextMap(int nextMapNumber)
|
|||
m_playerInitPos = nextMap.playerInitPos * TILE_SIZE * TILEMAP_SCALE;
|
||||
}
|
||||
|
||||
// Load a tileset
|
||||
void TileMap::LoadTileset(const string &path)
|
||||
{
|
||||
m_tileset = Game::textureManager.LoadTexture(path);
|
||||
|
@ -184,6 +191,7 @@ void TileMap::LoadTileset(const string &path)
|
|||
m_tilesetHeight /= TILE_SIZE;
|
||||
}
|
||||
|
||||
// Draw corresponding layer
|
||||
void TileMap::draw(int layer)
|
||||
{
|
||||
if(layer == 1)
|
||||
|
@ -205,6 +213,7 @@ void TileMap::draw(int layer)
|
|||
}
|
||||
}
|
||||
|
||||
// Draw the layer given
|
||||
void TileMap::m_draw(const vector<TileID> &tiles)
|
||||
{
|
||||
SDL_Rect visibleTilesR;
|
||||
|
@ -230,11 +239,13 @@ void TileMap::m_draw(const vector<TileID> &tiles)
|
|||
}
|
||||
}
|
||||
|
||||
// Get loaded player inital position
|
||||
Vector2D<float> TileMap::getPlayerInitPos()
|
||||
{
|
||||
return m_playerInitPos;
|
||||
}
|
||||
|
||||
// Destroy texture renderer
|
||||
TileMap::~TileMap()
|
||||
{
|
||||
if(Game::textureRenderer != NULL) SDL_DestroyTexture(Game::textureRenderer);
|
||||
|
|
Loading…
Reference in New Issue