Progresos con las rampas

This commit is contained in:
2022-09-06 20:37:39 +02:00
parent 066a9ab811
commit 9af135100c
7 changed files with 89 additions and 38 deletions

View File

@@ -242,18 +242,37 @@ void Player::move()
else
{
tile_e slope = checkSlopes();
debug->add("SLOPE = " + std::to_string(slope));
tile_e slope2 = checkSlopes2();
debug->add("SLOPE = " + std::to_string(slope));
debug->add("SLOPE2 = " + std::to_string(slope2));
if (slope != t_empty)
{ // Cuesta hacia la derecha
if (slope == t_slope_r)
{ // Recoloca
y = -h + room->getSlopeHeight(feet[1], t_slope_r);
debug->add("feet[1] = " + std::to_string(feet[1].y));
}
// Cuesta hacia la izquierda
if (slope == t_slope_l)
{ // Recoloca
y = -h + room->getSlopeHeight(feet[0], t_slope_l);
debug->add("feet[0] = " + std::to_string(feet[0].y));
}
}
else if (slope2 != t_empty)
{ // Cuesta hacia la derecha
if (slope2 == t_slope_r)
{ // Recoloca
y = -h + room->getSlopeHeight(underFeet[1], t_slope_r);
debug->add("ufeet[1] = " + std::to_string(underFeet[1].y));
}
// Cuesta hacia la izquierda
if (slope2 == t_slope_l)
{ // Recoloca
y = -h + room->getSlopeHeight(underFeet[0], t_slope_l);
debug->add("ufeet[0] = " + std::to_string(underFeet[0].y));
}
}
}
@@ -295,7 +314,7 @@ void Player::move()
vy = 0.0f;
// Si ademas ha habido un cambio de tile recoloca al jugador
if (tile_change)
if (tile_change && !checkSlopes2())
{
y = ((int)y - ((int)y % tileSize));
}
@@ -428,6 +447,44 @@ tile_e Player::checkSlopes()
return t_empty;
}
// Comprueba si el jugador está en una rampa
tile_e Player::checkSlopes2()
{
// Actualiza los puntos de colisión
updateFeet();
bool slope_l = false;
bool slope_r = false;
bool wall = false;
bool passable = 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);
wall |= (room->getTile(f) == t_wall);
passable |= (room->getTile(f) == t_passable);
}
if (wall || passable)
{
return t_empty;
}
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()
{