Las colisiones siguen fallando

This commit is contained in:
2022-09-08 23:33:46 +02:00
parent 98916cd1be
commit 197bf71c12
5 changed files with 64 additions and 65 deletions

View File

@@ -444,7 +444,7 @@ void Room::fillMapTexture()
{
clip.x = x * 8;
clip.y = y * 8;
SDL_SetRenderDrawColor(renderer, 48, 48, 48, 192);
SDL_SetRenderDrawColor(renderer, 48, 48, 48, 224);
SDL_RenderFillRect(renderer, &clip);
}
}
@@ -453,41 +453,45 @@ void Room::fillMapTexture()
// ****
if (debug->getEnabled())
{
// BottomSurfaces
if (true)
{
for (auto l : bottomSurfaces)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 80, (rand() % 128) + 80, (rand() % 128) + 80, 0xFF);
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
}
}
// TopSurfaces
if (true)
{
SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
for (auto l : topSurfaces)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 80, (rand() % 128) + 80, (rand() % 128) + 80, 0xFF);
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
}
}
// LeftSurfaces
if (true)
{
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
for (auto l : leftSurfaces)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 80, (rand() % 128) + 80, (rand() % 128) + 80, 0xFF);
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
}
}
// RightSurfaces
if (true)
{
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
for (auto l : rightSurfaces)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 80, (rand() % 128) + 80, (rand() % 128) + 80, 0xFF);
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 96, (rand() % 128) + 96, (rand() % 128) + 96, 0xFF);
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
}
}
@@ -864,7 +868,7 @@ void Room::setRightSurfaces()
while (i < tile.size())
{
v_line_t line;
line.x = (tile[i] % mapWidth) * tileSize + tileSize;
line.x = (tile[i] % mapWidth) * tileSize + tileSize - 1;
line.y1 = ((tile[i] / mapWidth) * tileSize);
while (tile[i] + mapWidth == tile[i + 1])
{
@@ -879,88 +883,69 @@ void Room::setRightSurfaces()
// Comprueba las colisiones
int Room::checkRightSurfaces(SDL_Rect *rect)
{
bool collision = false;
int pos = -1;
for (auto s : rightSurfaces)
{
collision = checkCollision(s, *rect);
if (collision)
if (checkCollision(s, *rect))
{
pos = s.x;
break;
return s.x;
}
}
return pos;
return -1;
}
// Comprueba las colisiones
int Room::checkLeftSurfaces(SDL_Rect *rect)
{
bool collision = false;
int pos = -1;
for (auto s : leftSurfaces)
{
collision = checkCollision(s, *rect);
if (collision)
if (checkCollision(s, *rect))
{
pos = s.x;
break;
return s.x;
}
}
return pos;
return -1;
}
// Comprueba las colisiones
int Room::checkTopSurfaces(SDL_Rect *rect)
{
bool collision = false;
int pos = -1;
for (auto s : topSurfaces)
{
collision = checkCollision(s, *rect);
if (collision)
if (checkCollision(s, *rect))
{
pos = s.y;
break;
return s.y;
}
}
return pos;
return -1;
}
// Comprueba las colisiones
int Room::checkBottomSurfaces(SDL_Rect *rect)
{
bool collision = false;
int pos = -1;
for (auto s : bottomSurfaces)
{
collision = checkCollision(s, *rect);
if (collision)
if (checkCollision(s, *rect))
{
pos = s.y;
break;
return s.y;
}
}
return pos;
return -1;
}
// Comprueba las colisiones
bool Room::checkTopSurfaces(SDL_Point *p)
{
bool collision = false;
for (auto s : topSurfaces)
{
collision |= checkCollision(s, *p);
if (checkCollision(s, *p))
{
return true;
}
}
return collision;
return false;
}