From 8ae821733c1c3847fbe45a45b980a79cdacf0f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Mon, 7 Nov 2022 17:00:48 +0100 Subject: [PATCH] =?UTF-8?q?Resuelto=20un=20bug=20con=20la=20detecci=C3=B3n?= =?UTF-8?q?=20de=20superficies?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/director.cpp | 2 +- source/game.cpp | 8 +++---- source/room.cpp | 56 +++++++++++++++++++++++++++------------------ 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/source/director.cpp b/source/director.cpp index 8bc587b..835f119 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -9,7 +9,7 @@ Director::Director(int argc, char *argv[]) section.name = SECTION_PROG_LOGO; section.subsection = SUBSECTION_LOGO_TO_INTRO; - //section.name = SECTION_PROG_GAME; + section.name = SECTION_PROG_GAME; // Crea e inicializa las opciones del programa iniOptions(); diff --git a/source/game.cpp b/source/game.cpp index e539a74..b98b734 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -19,10 +19,10 @@ Game::Game(SDL_Renderer *renderer, Screen *screen, Resource *resource, Asset *as this->options = options; // **** - //currentRoom = "03.room"; - //const int x = 29; - //const int y = 13; - //spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; + currentRoom = "03.room"; + const int x = 29; + const int y = 13; + spawnPoint = {x * 8, y * 8, 0, 0, 0, s_standing, SDL_FLIP_HORIZONTAL}; // **** // Crea los objetos diff --git a/source/room.cpp b/source/room.cpp index ea9a47d..acb3792 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -796,10 +796,10 @@ bool Room::itemCollision(SDL_Rect &rect) { for (int i = 0; i < (int)items.size(); ++i) { - if (checkCollision(rect, items[i]->getCollider())) + if (checkCollision(rect, items.at(i)->getCollider())) { - itemTracker->addItem(name, items[i]->getPos()); - delete items[i]; + itemTracker->addItem(name, items.at(i)->getPos()); + delete items.at(i); items.erase(items.begin() + i); JA_PlaySound(itemSound); *itemsPicked = *itemsPicked + 1; @@ -911,8 +911,11 @@ void Room::setBottomSurfaces() } } + // Añade un terminador + tile.push_back(-1); + // Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies - if ((int)tile.size() > 0) + if ((int)tile.size() > 1) { int i = 0; int lastOne = 0; @@ -937,7 +940,7 @@ void Room::setBottomSurfaces() } } - line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1; + line.x2 = ((tile.at(lastOne) % mapWidth) * tileSize) + tileSize - 1; bottomSurfaces.push_back(line); if (i <= (int)tile.size() - 1) { @@ -971,8 +974,11 @@ void Room::setTopSurfaces() } } + // Añade un terminador + tile.push_back(-1); + // Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies - if ((int)tile.size() > 0) + if ((int)tile.size() > 1) { int i = 0; int lastOne = 0; @@ -997,7 +1003,7 @@ void Room::setTopSurfaces() } } - line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1; + line.x2 = ((tile.at(lastOne) % mapWidth) * tileSize) + tileSize - 1; topSurfaces.push_back(line); if (i <= (int)tile.size() - 1) { @@ -1029,10 +1035,13 @@ void Room::setLeftSurfaces() } } + // Añade un terminador + tile.push_back(-1); + // Recorre el vector de tiles buscando tiles consecutivos // (Los tiles de la misma columna, la diferencia entre ellos es de mapWidth) // para localizar las superficies - if ((int)tile.size() > 0) + if ((int)tile.size() > 1) { int i = 0; do @@ -1040,7 +1049,7 @@ void Room::setLeftSurfaces() v_line_t line; line.x = (tile.at(i) % mapWidth) * tileSize; line.y1 = ((tile.at(i) / mapWidth) * tileSize); - while (tile.at(i) + mapWidth == tile[i + 1]) + while (tile.at(i) + mapWidth == tile.at(i + 1)) { if (i == (int)tile.size() - 1) { @@ -1074,10 +1083,13 @@ void Room::setRightSurfaces() } } + // Añade un terminador + tile.push_back(-1); + // Recorre el vector de tiles buscando tiles consecutivos // (Los tiles de la misma columna, la diferencia entre ellos es de mapWidth) // para localizar las superficies - if ((int)tile.size() > 0) + if ((int)tile.size() > 1) { int i = 0; do @@ -1085,7 +1097,7 @@ void Room::setRightSurfaces() v_line_t line; line.x = ((tile.at(i) % mapWidth) * tileSize) + tileSize - 1; line.y1 = ((tile.at(i) / mapWidth) * tileSize); - while (tile.at(i) + mapWidth == tile[i + 1]) + while (tile.at(i) + mapWidth == tile.at(i + 1)) { if (i == (int)tile.size() - 1) { @@ -1120,14 +1132,14 @@ void Room::setLeftSlopes() while (found.size() > 0) { d_line_t line; - line.x1 = (found[0] % mapWidth) * tileSize; - line.y1 = (found[0] / mapWidth) * tileSize; - int lookingFor = found[0] + mapWidth + 1; - int lastOneFound = found[0]; + line.x1 = (found.at(0) % mapWidth) * tileSize; + line.y1 = (found.at(0) / mapWidth) * tileSize; + int lookingFor = found.at(0) + mapWidth + 1; + int lastOneFound = found.at(0); found.erase(found.begin()); for (int i = 0; i < (int)found.size(); ++i) { - if (found[i] == lookingFor) + if (found.at(i) == lookingFor) { lastOneFound = lookingFor; lookingFor += mapWidth + 1; @@ -1161,14 +1173,14 @@ void Room::setRightSlopes() while (found.size() > 0) { d_line_t line; - line.x1 = ((found[0] % mapWidth) * tileSize) + tileSize - 1; - line.y1 = (found[0] / mapWidth) * tileSize; - int lookingFor = found[0] + mapWidth - 1; - int lastOneFound = found[0]; + line.x1 = ((found.at(0) % mapWidth) * tileSize) + tileSize - 1; + line.y1 = (found.at(0) / mapWidth) * tileSize; + int lookingFor = found.at(0) + mapWidth - 1; + int lastOneFound = found.at(0); found.erase(found.begin()); for (int i = 0; i < (int)found.size(); ++i) { - if (found[i] == lookingFor) + if (found.at(i) == lookingFor) { lastOneFound = lookingFor; lookingFor += mapWidth - 1; @@ -1229,7 +1241,7 @@ void Room::setAutoSurfaces() } } - line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1; + line.x2 = ((tile.at(lastOne) % mapWidth) * tileSize) + tileSize - 1; autoSurfaces.push_back(line); if (i <= (int)tile.size() - 1) {