Terminado el cálculo de superficies

This commit is contained in:
2022-09-07 22:47:22 +02:00
parent a73c11effa
commit 044cf97857
7 changed files with 139 additions and 57 deletions

View File

@@ -441,31 +441,34 @@ void Room::fillMapTexture()
}
// ****
SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
for (auto l : bottomSurfaces)
if (debug->getEnabled())
{
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
}
SDL_SetRenderDrawColor(renderer, 0x00, 0xFF, 0x00, 0xFF);
for (auto l : bottomSurfaces)
{
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
}
SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
for (auto l : topSurfaces)
{
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
}
SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
for (auto l : topSurfaces)
{
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
}
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
for (auto l : leftSurfaces)
{
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
}
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
for (auto l : leftSurfaces)
{
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
}
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
for (auto l : rightSurfaces)
{
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
for (auto l : rightSurfaces)
{
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
}
}
// ****
SDL_SetRenderTarget(renderer, nullptr);
}
@@ -704,9 +707,15 @@ void Room::setBottomSurfaces()
// tienen un tile de tipo vacio
for (int i = 0; i < tilemap.size() - mapWidth; i++)
{
if (getTile(i) == t_wall && getTile(i + mapWidth) == t_empty)
if (getTile(i) == t_wall && getTile(i + mapWidth) != t_wall)
{
tile.push_back(i);
// Si llega al final de la fila, introduce un separador
if (i % mapWidth == mapWidth - 1)
{
tile.push_back(-1);
}
}
}
@@ -717,9 +726,14 @@ void Room::setBottomSurfaces()
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
while (tile[i] + 1 == tile[i + 1])
{
i++;
if (i % mapWidth == mapWidth - 1)
{
break;
}
}
line.x2 = ((tile[i] % mapWidth) * tileSize) + tileSize - 1;
bottomSurfaces.push_back(line);
@@ -736,9 +750,15 @@ void Room::setTopSurfaces()
// tienen un tile de tipo vacio
for (int i = mapWidth; i < tilemap.size(); i++)
{
if (getTile(i) == t_wall && getTile(i - mapWidth) == t_empty)
if ((getTile(i) == t_wall || getTile(i) == t_passable) && getTile(i - mapWidth) != t_wall)
{
tile.push_back(i);
// Si llega al final de la fila, introduce un separador
if (i % mapWidth == mapWidth - 1)
{
tile.push_back(-1);
}
}
}
@@ -752,6 +772,10 @@ void Room::setTopSurfaces()
while (tile[i] + 1 == tile[i + 1])
{
i++;
if (i % mapWidth == mapWidth - 1)
{
break;
}
}
line.x2 = ((tile[i] % mapWidth) * tileSize) + tileSize - 1;
topSurfaces.push_back(line);
@@ -770,7 +794,7 @@ void Room::setLeftSurfaces()
{
if (i % mapWidth != 0)
{
if (getTile(i) == t_wall && getTile(i - 1) == t_empty)
if (getTile(i) == t_wall && getTile(i - 1) != t_wall)
{
tile.push_back(i);
}
@@ -784,11 +808,11 @@ void Room::setLeftSurfaces()
v_line_t line;
line.x = (tile[i] % mapWidth) * tileSize;
line.y1 = ((tile[i] / mapWidth) * tileSize);
while (tile[i] + 1 == tile[i + mapWidth])
while (tile[i] + mapWidth == tile[i + 1])
{
i++;
}
line.x2 = ((tile[i] % mapWidth) * tileSize) + tileSize - 1;
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
leftSurfaces.push_back(line);
i++;
}
@@ -797,4 +821,34 @@ void Room::setLeftSurfaces()
// Calcula las superficies laterales derechas
void Room::setRightSurfaces()
{
std::vector<int> tile;
// Busca todos los tiles de tipo wall (excepto los de la ultima columna) que a su derecha
// tienen un tile de tipo vacio
for (int i = 0; i < tilemap.size(); i++)
{
if (i % mapWidth != mapWidth - 1)
{
if (getTile(i) == t_wall && getTile(i + 1) != t_wall)
{
tile.push_back(i);
}
}
}
// Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies
int i = 0;
while (i < tile.size())
{
v_line_t line;
line.x = (tile[i] % mapWidth) * tileSize + tileSize;
line.y1 = ((tile[i] / mapWidth) * tileSize);
while (tile[i] + mapWidth == tile[i + 1])
{
i++;
}
line.y2 = ((tile[i] / mapWidth) * tileSize) + tileSize - 1;
rightSurfaces.push_back(line);
i++;
}
}