Corregido un bug con las colisiones entre un punto y una linea diagonal

This commit is contained in:
2022-09-14 21:18:50 +02:00
parent 2ff12f7db1
commit d5e5d142a4
10 changed files with 97 additions and 25 deletions

View File

@@ -126,7 +126,6 @@ void Player::render()
// Pinta el rectangulo de movimiento
SDL_SetRenderDrawColor(renderer, 255, 0, 0, 255);
SDL_RenderFillRect(renderer, &r);
debug->add("RECT: " + std::to_string(r.x) + "," + std::to_string(r.y) + "," + std::to_string(r.w) + "," + std::to_string(r.h));
}
}
@@ -454,6 +453,8 @@ void Player::move()
// Actualiza la posición del sprite
sprite->setPosX(x);
sprite->setPosY(y);
debug->add("RECT: " + std::to_string(r.x) + "," + std::to_string(r.y) + "," + std::to_string(r.w) + "," + std::to_string(r.h));
}
// Establece la animación del jugador
@@ -506,6 +507,8 @@ void Player::playFallSound()
bool Player::isOnFloor()
{
bool onFloor = false;
bool onSlopeL = false;
bool onSlopeR = false;
updateFeet();
@@ -516,15 +519,25 @@ bool Player::isOnFloor()
}
// Comprueba las rampas
onFloor |= room->checkLeftSlopes(&underFeet[0]);
onFloor |= room->checkRightSlopes(&underFeet[1]);
onSlopeL = room->checkLeftSlopes(&underFeet[0]);
onSlopeR = room->checkRightSlopes(&underFeet[1]);
if (onFloor)
{
debug->add("ONFLOOR");
debug->add("ON_FLOOR");
}
return onFloor;
if (onSlopeL)
{
debug->add("ON_SLOPE_L: " + std::to_string(underFeet[0].x) + "," + std::to_string(underFeet[0].y));
}
if (onSlopeR)
{
debug->add("ON_SLOPE_R: " + std::to_string(underFeet[1].x) + "," + std::to_string(underFeet[1].y));
}
return onFloor || onSlopeL || onSlopeR;
}
// Comprueba si el jugador está sobre una rampa hacia abajo
@@ -545,7 +558,7 @@ bool Player::isOnDownSlope()
if (onSlope)
{
debug->add("ONSLOPE");
debug->add("ON_DOWN_SLOPE");
}
return onSlope;