Colisiones

This commit is contained in:
2022-09-09 07:53:57 +02:00
parent 197bf71c12
commit 00b47a5910
2 changed files with 10 additions and 10 deletions

View File

@@ -244,9 +244,9 @@ void Player::move()
proj.w = (int)vx;
// **new
proj.x = (int)(x+vx);
proj.x = (int)(x + vx);
proj.y = (int)y;
proj.h = h;
proj.h = h - 1;
proj.w = (int)abs(vx);
// Comprueba la colisión
@@ -264,13 +264,13 @@ void Player::move()
}
// Se mueve hacia la derecha
if (vx > 0.0f)
else if (vx > 0.0f)
{
// Crea el rectangulo de proyección en el eje X para ver si colisiona
SDL_Rect proj;
proj.x = (int)x + w;
proj.y = (int)y;
proj.h = h;
proj.h = h - 1;
proj.w = (int)(vx);
// Comprueba la colisión
@@ -305,9 +305,9 @@ void Player::move()
// **new
proj.x = (int)x;
proj.y = (int)(y+vy);
proj.y = (int)(y + vy);
proj.h = (int)abs(vy);
proj.w = w;
proj.w = w - 1;
// Comprueba la colisión
const int pos = room->checkBottomSurfaces(&proj);
@@ -332,7 +332,7 @@ void Player::move()
proj.x = (int)x;
proj.y = (int)y + h;
proj.h = (int)vy;
proj.w = w;
proj.w = w - 1;
// Comprueba la colisión
const int pos = room->checkTopSurfaces(&proj);

View File

@@ -158,7 +158,7 @@ bool checkCollision(h_line_t &l, SDL_Rect &r)
}
// Comprueba si el inicio de la linea esta a la derecha del rectangulo
if (l.x1 >= r.x + r.w)
if (l.x1 > r.x + r.w)
{
return false;
}