Completadas las colisiones y estados

This commit is contained in:
2022-09-08 21:31:51 +02:00
parent 88d6471dc8
commit 98916cd1be
7 changed files with 153 additions and 69 deletions

View File

@@ -437,14 +437,14 @@ void Room::fillMapTexture()
{
clip.x = ((tilemap[(y * 32) + x] - 1) % 20) * 8;
clip.y = ((tilemap[(y * 32) + x] - 1) / 20) * 8;
// texture->render(renderer, x * 8, y * 8, &clip);
texture->render(renderer, x * 8, y * 8, &clip);
if (debug->getEnabled())
{
if (clip.x != -8)
{
clip.x = x * 8;
clip.y = y * 8;
SDL_SetRenderDrawColor(renderer, 32, 32, 32, 0xFF);
SDL_SetRenderDrawColor(renderer, 48, 48, 48, 192);
SDL_RenderFillRect(renderer, &clip);
}
}
@@ -453,31 +453,43 @@ void Room::fillMapTexture()
// ****
if (debug->getEnabled())
{
for (auto l : bottomSurfaces)
if (true)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 80, (rand() % 128) + 80, (rand() % 128) + 80, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
for (auto l : bottomSurfaces)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 80, (rand() % 128) + 80, (rand() % 128) + 80, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
}
}
SDL_SetRenderDrawColor(renderer, 0xFF, 0x00, 0x00, 0xFF);
for (auto l : topSurfaces)
if (true)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 80, (rand() % 128) + 80, (rand() % 128) + 80, 0xFF);
SDL_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
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_RenderDrawLine(renderer, l.x1, l.y, l.x2, l.y);
}
}
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0xFF);
for (auto l : leftSurfaces)
if (true)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 80, (rand() % 128) + 80, (rand() % 128) + 80, 0xFF);
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
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_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
}
}
SDL_SetRenderDrawColor(renderer, 0xFF, 0xFF, 0xFF, 0xFF);
for (auto l : rightSurfaces)
if (true)
{
SDL_SetRenderDrawColor(renderer, (rand() % 128) + 80, (rand() % 128) + 80, (rand() % 128) + 80, 0xFF);
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
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_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
}
}
}
// ****
@@ -938,4 +950,17 @@ int Room::checkBottomSurfaces(SDL_Rect *rect)
}
return pos;
}
// Comprueba las colisiones
bool Room::checkTopSurfaces(SDL_Point *p)
{
bool collision = false;
for (auto s : topSurfaces)
{
collision |= checkCollision(s, *p);
}
return collision;
}