ajustant al jugador
This commit is contained in:
@@ -201,7 +201,7 @@ void Player::updateOnAir(float delta_time) {
|
||||
// Movimiento físico del estado ON_GROUND
|
||||
void Player::moveOnGround(float delta_time) {
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wanna_go_
|
||||
updateVelocity();
|
||||
updateVelocity(delta_time);
|
||||
|
||||
if (vx_ == 0.0F) { return; }
|
||||
|
||||
@@ -233,7 +233,7 @@ void Player::moveOnGround(float delta_time) {
|
||||
// Movimiento físico del estado ON_SLOPE
|
||||
void Player::moveOnSlope(float delta_time) {
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wanna_go_
|
||||
updateVelocity();
|
||||
updateVelocity(delta_time);
|
||||
|
||||
// Verificar rampa válida antes de comprobar velocidad: si no hay rampa siempre caer,
|
||||
// independientemente de si hay o no input (evita bloqueo con vx_=0 y slope null)
|
||||
@@ -320,7 +320,7 @@ void Player::moveOnSlope(float delta_time) {
|
||||
// El jugador puede moverse horizontalmente en el aire y la gravedad siempre actúa.
|
||||
void Player::moveOnAir(float delta_time) {
|
||||
// Movimiento horizontal libre según wanna_go_ (permite girar en el aire)
|
||||
updateVelocity();
|
||||
updateVelocity(delta_time);
|
||||
applyHorizontalMovement(delta_time);
|
||||
|
||||
// Gravedad
|
||||
@@ -649,31 +649,31 @@ void Player::placeSprite() {
|
||||
sprite_->setPos(x_, y_);
|
||||
}
|
||||
|
||||
// Calcula la velocidad en x
|
||||
void Player::updateVelocity() {
|
||||
// Calcula la velocidad en x con inercia ligera (interpolación hacia vel. objetivo)
|
||||
void Player::updateVelocity(float delta_time) {
|
||||
float target = 0.0F;
|
||||
if (auto_movement_) {
|
||||
// La cinta transportadora tiene el control
|
||||
vx_ = HORIZONTAL_VELOCITY * room_->getConveyorBeltDirection();
|
||||
sprite_->setFlip(vx_ < 0.0F ? Flip::LEFT : Flip::RIGHT);
|
||||
target = HORIZONTAL_VELOCITY * room_->getConveyorBeltDirection();
|
||||
} else {
|
||||
// El jugador tiene el control
|
||||
switch (wanna_go_) {
|
||||
case Direction::LEFT:
|
||||
vx_ = -HORIZONTAL_VELOCITY;
|
||||
sprite_->setFlip(Flip::LEFT);
|
||||
break;
|
||||
case Direction::RIGHT:
|
||||
vx_ = HORIZONTAL_VELOCITY;
|
||||
sprite_->setFlip(Flip::RIGHT);
|
||||
break;
|
||||
case Direction::NONE:
|
||||
vx_ = 0.0F;
|
||||
break;
|
||||
default:
|
||||
vx_ = 0.0F;
|
||||
break;
|
||||
case Direction::LEFT: target = -HORIZONTAL_VELOCITY; break;
|
||||
case Direction::RIGHT: target = HORIZONTAL_VELOCITY; break;
|
||||
default: target = 0.0F; break;
|
||||
}
|
||||
}
|
||||
|
||||
// Orientación del sprite según la dirección deseada (sin cambiar cuando target=0)
|
||||
if (target > 0.0F) { sprite_->setFlip(Flip::RIGHT); }
|
||||
else if (target < 0.0F) { sprite_->setFlip(Flip::LEFT); }
|
||||
|
||||
// Aproximar vx_ al objetivo con paso limitado por la aceleración
|
||||
const float STEP = HORIZONTAL_ACCEL * delta_time;
|
||||
if (vx_ < target) {
|
||||
vx_ = std::min(vx_ + STEP, target);
|
||||
} else if (vx_ > target) {
|
||||
vx_ = std::max(vx_ - STEP, target);
|
||||
}
|
||||
}
|
||||
|
||||
// Aplica movimiento horizontal con colisión de muros
|
||||
|
||||
Reference in New Issue
Block a user