Las superficies automaticas ya arrastran. Falta definir el sentido y la animación

This commit is contained in:
2022-09-25 14:09:37 +02:00
parent 8a4d2a541d
commit dea16e0004
4 changed files with 166 additions and 18 deletions

View File

@@ -38,6 +38,7 @@ Room::Room(std::string file, SDL_Renderer *renderer, Screen *screen, Asset *asse
setRightSurfaces();
setLeftSlopes();
setRightSlopes();
setAutoSurfaces();
// Busca los tiles animados
setAnimatedTiles();
@@ -582,6 +583,7 @@ void Room::fillMapTexture()
for (auto l : leftSurfaces)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 0, 0, 255, 0xFF);
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
}
}
@@ -592,6 +594,7 @@ void Room::fillMapTexture()
for (auto l : rightSurfaces)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 255, 255, 0, 0xFF);
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
}
}
@@ -602,6 +605,7 @@ void Room::fillMapTexture()
for (auto l : leftSlopes)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 0, 255, 255, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y1, l.x2, l.y2);
}
}
@@ -612,9 +616,20 @@ void Room::fillMapTexture()
for (auto l : rightSlopes)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_SetRenderDrawColor(renderer, 255, 0, 255, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y1, l.x2, l.y2);
}
}
// AutoSurfaces
if (true)
{
for (auto l : autoSurfaces)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
}
}
}
// ****
@@ -628,7 +643,10 @@ void Room::renderMap()
SDL_RenderCopy(renderer, mapTexture, nullptr, nullptr);
// Dibuja los tiles animados
renderAnimatedTiles();
if (!debug->getEnabled())
{
renderAnimatedTiles();
}
}
// Dibuja los enemigos en pantalla
@@ -1087,6 +1105,53 @@ void Room::setRightSlopes()
}
}
// Calcula las superficies automaticas
void Room::setAutoSurfaces()
{
std::vector<int> tile;
// Busca todos los tiles de tipo animado
// Hay que recorrer la habitación por filas (excepto los de la primera fila)
for (int i = mapWidth; i < (int)tilemap.size(); ++i)
{
if (getTile(i) == t_animated)
{
tile.push_back(i);
// Si llega al final de la fila, introduce un separador
if (i % mapWidth == mapWidth - 1)
{
tile.push_back(-1);
}
}
}
// Recorre el vector de tiles buscando tiles consecutivos para localizar las superficies
int i = 0;
int lastOne = 0;
while (i < (int)tile.size())
{
h_line_t line;
line.x1 = (tile[i] % mapWidth) * tileSize;
line.y = (tile[i] / mapWidth) * tileSize;
lastOne = i;
i++;
while (tile[i] == tile[i - 1] + 1)
{
lastOne = i;
i++;
}
line.x2 = ((tile[lastOne] % mapWidth) * tileSize) + tileSize - 1;
autoSurfaces.push_back(line);
if (tile[i] == -1)
{ // Si el siguiente elemento es un separador, hay que saltarlo
i++;
}
}
}
// Localiza todos los tiles animados de la habitación
void Room::setAnimatedTiles()
{
@@ -1190,6 +1255,20 @@ int Room::checkBottomSurfaces(SDL_Rect *rect)
return -1;
}
// Comprueba las colisiones
int Room::checkAutoSurfaces(SDL_Rect *rect)
{
for (auto s : autoSurfaces)
{
if (checkCollision(s, *rect))
{
return s.y;
}
}
return -1;
}
// Comprueba las colisiones
bool Room::checkTopSurfaces(SDL_Point *p)
{
@@ -1204,6 +1283,20 @@ bool Room::checkTopSurfaces(SDL_Point *p)
return false;
}
// Comprueba las colisiones
bool Room::checkAutoSurfaces(SDL_Point *p)
{
for (auto s : autoSurfaces)
{
if (checkCollision(s, *p))
{
return true;
}
}
return false;
}
// Comprueba las colisiones
int Room::checkLeftSlopes(v_line_t *line)
{