Trabajando en las colisiones y estados

This commit is contained in:
2022-09-08 14:09:05 +02:00
parent 9fc4c2d8b0
commit 88d6471dc8
4 changed files with 208 additions and 9 deletions

View File

@@ -476,7 +476,7 @@ void Room::fillMapTexture()
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) + 80, (rand() % 128) + 80, (rand() % 128) + 80, 0xFF);
SDL_RenderDrawLine(renderer, l.x, l.y1, l.x, l.y2);
}
}
@@ -862,4 +862,80 @@ void Room::setRightSurfaces()
rightSurfaces.push_back(line);
i++;
}
}
// 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)
{
pos = s.x;
break;
}
}
return pos;
}
// 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)
{
pos = s.x;
break;
}
}
return pos;
}
// 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)
{
pos = s.y;
break;
}
}
return pos;
}
// 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)
{
pos = s.y;
break;
}
}
return pos;
}