diff --git a/source/room.cpp b/source/room.cpp index 12364d1..59187d9 100644 --- a/source/room.cpp +++ b/source/room.cpp @@ -778,19 +778,28 @@ void Room::setBottomSurfaces() // Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies int i = 0; + int lastOne = 0; while (i < tile.size()) { h_line_t line; line.x1 = (tile[i] % mapWidth) * tileSize; line.y = ((tile[i] / mapWidth) * tileSize) + tileSize - 1; + lastOne = i; + i++; - while (tile[i] + 1 == tile[i + 1]) + while (tile[i] == tile[i - 1] + 1) { + lastOne = i; i++; } - line.x2 = ((tile[i] % mapWidth) * tileSize) + tileSize - 1; + + line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1; bottomSurfaces.push_back(line); - i++; + if (tile[i] == -1) + { // Si el siguiente elemento es un separador, hay que saltarlo + i++; + } + debug->addToLog("B: " + std::to_string(line.x1) + "," + std::to_string(line.y) + "," + std::to_string(line.x2) + "," + std::to_string(line.y)); } } @@ -820,18 +829,27 @@ void Room::setTopSurfaces() // Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies int i = 0; + int lastOne = 0; while (i < tile.size()) { h_line_t line; line.x1 = (tile[i] % mapWidth) * tileSize; line.y = (tile[i] / mapWidth) * tileSize; - while (tile[i] + 1 == tile[i + 1]) + lastOne = i; + i++; + + while (tile[i] == tile[i - 1] + 1) { + lastOne = i; i++; } - line.x2 = ((tile[i] % mapWidth) * tileSize) + tileSize - 1; + + line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1; topSurfaces.push_back(line); - i++; + if (tile[i] == -1) + { // Si el siguiente elemento es un separador, hay que saltarlo + i++; + } debug->addToLog("T: " + std::to_string(line.x1) + "," + std::to_string(line.y) + "," + std::to_string(line.x2) + "," + std::to_string(line.y)); } @@ -909,7 +927,6 @@ void Room::setRightSurfaces() } line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1; rightSurfaces.push_back(line); - i++; } }