Solucion con checkUpSlopes y checkDownSlopes. No funciona

This commit is contained in:
2022-09-06 11:06:09 +02:00
parent ce8a4a8050
commit 16ae06a755
2 changed files with 62 additions and 13 deletions

View File

@@ -240,17 +240,34 @@ void Player::move()
// Comprueba colisiones con rampas
else
{
const tile_e slope = checkSlopes();
// Se mueve hacia la derecha y cuesta hacia la derecha
if (sprite->getFlip() == SDL_FLIP_NONE && slope == t_slope_r)
{ // Recoloca
y = -h + room->getSlopeHeight(feet[1], t_slope_r);
tile_e slope = checkUpSlopes();
if (slope != t_empty)
{ // Se mueve hacia la derecha y cuesta hacia la derecha
if (sprite->getFlip() == SDL_FLIP_NONE && slope == t_slope_r)
{ // Recoloca
y = -h + room->getSlopeHeight(feet[1], t_slope_r);
}
// Se mueve hacia la izquierda y cuesta hacia la izquierda
if (sprite->getFlip() == SDL_FLIP_HORIZONTAL && slope == t_slope_l)
{ // Recoloca
y = -h + room->getSlopeHeight(feet[0], t_slope_l);
}
}
// Se mueve hacia la izquierda y cuesta hacia la izquierda
if (sprite->getFlip() == SDL_FLIP_HORIZONTAL && slope == t_slope_l)
{ // Recoloca
y = -h + room->getSlopeHeight(feet[0], t_slope_l);
slope = checkDownSlopes();
if (slope != t_empty)
{ // Se mueve hacia la derecha y cuesta hacia la izquierda
if (sprite->getFlip() == SDL_FLIP_NONE && slope == t_slope_l)
{ // Recoloca
y = -h + room->getSlopeHeight(underFeet[0], t_slope_l);
}
// Se mueve hacia la izquierda y cuesta hacia la derecha
if (sprite->getFlip() == SDL_FLIP_HORIZONTAL && slope == t_slope_r)
{ // Recoloca
y = -h + room->getSlopeHeight(underFeet[1], t_slope_r);
}
}
}
@@ -328,7 +345,7 @@ void Player::move()
}
}
// EXPERIMENTAL
else if (checkSlopes())
else if (checkUpSlopes() || checkDownSlopes())
{
state = s_standing;
vy = 0.0f;
@@ -396,15 +413,15 @@ bool Player::checkWalls()
}
// Comprueba si el jugador está en una rampa
tile_e Player::checkSlopes()
tile_e Player::checkUpSlopes()
{
// Actualiza los puntos de colisión
updateFeet();
// Comprueba si ha colisionado con una rampa
bool slope_l = false;
bool slope_r = false;
// Comprueba si ha colisionado con una rampa
for (auto f : feet)
{
slope_l |= (room->getTile(f) == t_slope_l);
@@ -424,6 +441,35 @@ tile_e Player::checkSlopes()
return t_empty;
}
// Comprueba si el jugador está en una rampa
tile_e Player::checkDownSlopes()
{
// Actualiza los puntos de colisión
updateFeet();
bool slope_l = false;
bool slope_r = false;
// Comprueba si ha colisionado con una rampa
for (auto f : underFeet)
{
slope_l |= (room->getTile(f) == t_slope_l);
slope_r |= (room->getTile(f) == t_slope_r);
}
if (slope_l)
{
return t_slope_l;
}
if (slope_r)
{
return t_slope_r;
}
return t_empty;
}
// Obtiene algunos parametros del jugador
player_t Player::getSpawnParams()
{

View File

@@ -91,7 +91,10 @@ public:
bool checkWalls();
// Comprueba si el jugador está en una rampa
tile_e checkSlopes();
tile_e checkUpSlopes();
// Comprueba si el jugador está en una rampa
tile_e checkDownSlopes();
// Actualiza los puntos de colisión
void updateColliderPoints();