Terminadas las nuevas colisiones. Ya no se detiene al colisionar horizontalmente

This commit is contained in:
2022-09-04 21:33:42 +02:00
parent 796a31a099
commit 73d394388b
2 changed files with 10 additions and 2 deletions

View File

@@ -244,18 +244,20 @@ void Player::move()
{ // Bajando
y -= ((int)y + h) % tileSize;
state = s_standing;
vy = 0.0f;
}
else
{ // Subiendo
y += tileSize - ((int)y % tileSize);
state = s_falling;
vy = maxVY;
}
}
else
// Si no colisiona con los muros, haz comprobaciones extra
{
const int a = (lastPosition.y + h) / tileSize;
const int b = ((int)y + h) / tileSize;
const int a = (lastPosition.y + h - 1) / tileSize;
const int b = ((int)y + h - 1) / tileSize;
const bool tile_change = a != b;
bool going_down = vy >= 0.0f;
@@ -268,6 +270,7 @@ void Player::move()
if (isOnFloor())
{ // Y deja al jugador de pie
state = s_standing;
vy = 0.0f;
// Si ademas ha habido un cambio de tile recoloca al jugador
if (tile_change)
@@ -280,6 +283,7 @@ void Player::move()
else if (state != s_jumping)
{
state = s_falling;
vy = maxVY;
}
}
@@ -292,6 +296,7 @@ void Player::move()
if (state != s_jumping)
{
state = s_falling;
vy = maxVY;
}
// Si está alineado con el tile mira el suelo (para que no lo mire si está
@@ -301,6 +306,7 @@ void Player::move()
if (isOnFloor())
{
state = s_standing;
vy = 0.0f;
}
}
}
@@ -334,6 +340,7 @@ void Player::checkJumpEnd()
if (y >= jump_ini)
{
state = s_falling;
vy = maxVY;
}
}