Plataformas moviles completadas
This commit is contained in:
@@ -198,8 +198,10 @@ void Player::move()
|
||||
lastPosition = {(int)x, (int)y};
|
||||
addGravity();
|
||||
|
||||
// Mueve en el eje X y comprueba colisiones con muros
|
||||
// Mueve en el eje X
|
||||
x += vx;
|
||||
|
||||
// Comprueba colisiones con muros
|
||||
if (checkMapCollisions())
|
||||
{
|
||||
// Recoloca
|
||||
@@ -215,6 +217,7 @@ void Player::move()
|
||||
vx = 0.0f;
|
||||
}
|
||||
|
||||
|
||||
// Mueve en el eje Y y comprueba colisiones con muros
|
||||
y += vy;
|
||||
if (checkMapCollisions())
|
||||
@@ -260,17 +263,26 @@ void Player::move()
|
||||
}
|
||||
}
|
||||
|
||||
// Si cayendo toca una plataforma movil
|
||||
// Si está cayendo
|
||||
if (vy >= 0.0f)
|
||||
{
|
||||
state = falling;
|
||||
|
||||
if (isOnFloor())
|
||||
{
|
||||
state = standing;
|
||||
}
|
||||
|
||||
// Si no esta enganchado a una plataforma
|
||||
if (hookedOnMovingPlatform == -1)
|
||||
{
|
||||
// Si esta sobre una plataforma
|
||||
if (isOnMovingPlatform())
|
||||
{
|
||||
// Detener la caída y alinearlo con la plataforma
|
||||
state = standing;
|
||||
vy = 0.0f;
|
||||
y = -h + map->getActorCollider(hookedOnMovingPlatform);
|
||||
y = -h + map->getActorCollider(hookedOnMovingPlatform).y;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,7 +293,9 @@ void Player::move()
|
||||
// Dejarlo alineado con la plataforma
|
||||
state = standing;
|
||||
vy = 0.0f;
|
||||
y = -h + map->getActorCollider(hookedOnMovingPlatform);
|
||||
y = -h + map->getActorCollider(hookedOnMovingPlatform).y;
|
||||
x += map->getActorIncX(hookedOnMovingPlatform);
|
||||
isOnMovingPlatform();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -333,13 +347,14 @@ bool Player::isOnFloor()
|
||||
bool Player::isOnMovingPlatform()
|
||||
{
|
||||
bool onMovingPlatform = false;
|
||||
hookedOnMovingPlatform = -1;
|
||||
|
||||
updateFeet();
|
||||
|
||||
for (auto f : underFeet)
|
||||
{
|
||||
onMovingPlatform |= (map->getActorName(map->actorCollision(f)) == a_moving_platform);
|
||||
hookedOnMovingPlatform = std::max(hookedOnMovingPlatform,(map->actorCollision(f)));
|
||||
hookedOnMovingPlatform = std::max(hookedOnMovingPlatform, (map->actorCollision(f)));
|
||||
}
|
||||
return onMovingPlatform;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user