From 516d57f7e05d4cedc97ece39688c9a35cb81b5ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Tom=C3=A1s?= Date: Thu, 30 Jun 2022 11:53:56 -0300 Subject: [PATCH] finished t3 --- header/TileMap.h | 1 + src/Face.cpp | 2 +- src/Resources.cpp | 7 +++---- src/State.cpp | 2 +- src/TileMap.cpp | 11 +++++++---- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/header/TileMap.h b/header/TileMap.h index ed68a67..1d6c8ec 100644 --- a/header/TileMap.h +++ b/header/TileMap.h @@ -16,6 +16,7 @@ class TileMap : public Component { bool Is(const char* type); void Render(); void RenderLayer(int layer, int cameraX = 0, int cameraY = 0); + ~TileMap(); int GetWidth(); int GetHeight(); int GetDepth(); diff --git a/src/Face.cpp b/src/Face.cpp index 5153bfa..d2f062e 100644 --- a/src/Face.cpp +++ b/src/Face.cpp @@ -18,7 +18,7 @@ void Face::Damage(int damage) cout << "HP is " << hitpoints << endl; } -// @TODO: como face e uma classe temporaria, o request delete foi +// Como face e uma classe temporaria, o request delete foi // movido de damage para update para melhorar o funcionamento do jogo. void Face::Update(float dt) { diff --git a/src/Resources.cpp b/src/Resources.cpp index fde50fa..ac344d0 100644 --- a/src/Resources.cpp +++ b/src/Resources.cpp @@ -21,8 +21,7 @@ SDL_Texture* Resources::GetImage(const char* file) else { - imageTable.insert(make_pair(file, texture)); - // imageTable[file] = texture; // @TODO: possible solution? + imageTable[file] = texture; cout << "\nTexture " << file << " loaded successfully!" << endl; return imageTable[file]; } @@ -44,7 +43,7 @@ Mix_Music* Resources::GetMusic(const char* file) else { - musicTable.insert(make_pair(file, music)); + musicTable[file] = music; cout << "\nMusic " << file << " loaded successfully!" << endl; return musicTable[file]; } @@ -66,7 +65,7 @@ Mix_Chunk* Resources::GetSound(const char* file) else { - soundTable.insert(make_pair(file, chunk)); + soundTable[file] = chunk; cout << "\nSound " << file << " loaded successfully!" << endl; return soundTable[file]; } diff --git a/src/State.cpp b/src/State.cpp index a28bf96..27aff31 100644 --- a/src/State.cpp +++ b/src/State.cpp @@ -11,7 +11,7 @@ State::State() : { // Tileset & Tilemap GameObject* tileGo = new GameObject(); - TileSet* tileSet = new TileSet(64, 64, "./assets/image/tileset.png"); // @TODO: delete tileset when finished + TileSet* tileSet = new TileSet(64, 64, "./assets/image/tileset.png"); TileMap* tileMap = new TileMap(*tileGo, "./assets/map/tileMap.txt", tileSet); tileGo->box.x = 0; diff --git a/src/TileMap.cpp b/src/TileMap.cpp index d19cefe..c6ce1d3 100644 --- a/src/TileMap.cpp +++ b/src/TileMap.cpp @@ -64,13 +64,11 @@ void TileMap::SetTileSet(TileSet* tileSet) int& TileMap::At(int x, int y, int z) { - // @TODO: check // Index = (W * H * Z) + (W * Y) + X unsigned index = x + (mapWidth * y) + (mapWidth * mapHeight * z); return tileMatrix[index]; } -// @TODO: check void TileMap::RenderLayer(int layer, int cameraX, int cameraY) { unsigned startPos = mapWidth * mapHeight * layer; @@ -91,8 +89,6 @@ void TileMap::RenderLayer(int layer, int cameraX, int cameraY) } } -// @TODO: why use the box? -// RenderLayer(i, associated.box.x, associated.box.y); void TileMap::Render() { for (auto i = 0; i < mapDepth; i++) @@ -110,6 +106,13 @@ bool TileMap::Is(const char* type) return (str_type == "TileMap"); } +// @TODO: needs to be changed when using multiple tilemaps for the same tileset! +TileMap::~TileMap() +{ + delete tileSet; + cout << "TileSet deleted successfully!" << endl; +} + int TileMap::GetWidth() { return mapWidth;