stule: el jugador no gira el sprite en el aire

This commit is contained in:
2026-04-08 18:09:41 +02:00
parent 88a822c562
commit 2a63227ee2
2 changed files with 24 additions and 10 deletions

View File

@@ -135,7 +135,7 @@ void Player::updateVelocity(float delta_time) {
break;
}
// Detectar cambio de dirección en el suelo
// Detectar cambio de dirección (solo en suelo — en el aire no se gira)
if (state_ != State::ON_AIR && target != 0.0F) {
Direction new_facing = (target > 0.0F) ? Direction::RIGHT : Direction::LEFT;
if (new_facing != facing_) {
@@ -145,20 +145,27 @@ void Player::updateVelocity(float delta_time) {
}
}
// Orientación del sprite
if (target > 0.0F) {
sprite_->setFlip(Flip::RIGHT);
} else if (target < 0.0F) {
sprite_->setFlip(Flip::LEFT);
// Orientación del sprite (solo en suelo, en el aire se mantiene la dirección del salto)
if (state_ != State::ON_AIR) {
if (target > 0.0F) {
sprite_->setFlip(Flip::RIGHT);
} else if (target < 0.0F) {
sprite_->setFlip(Flip::LEFT);
}
}
// Inercia: aire = gradual ambas direcciones, suelo = instantáneo arranque, gradual frenada
const float STEP = HORIZONTAL_ACCEL * delta_time;
if (state_ == State::ON_AIR) {
if (vx_ < target) {
vx_ = std::min(vx_ + STEP, target);
} else if (vx_ > target) {
vx_ = std::max(vx_ - STEP, target);
// En el aire, permitir mantener velocidad boosteada si vamos en la misma dirección
float air_target = target;
if ((target > 0.0F && vx_ > target) || (target < 0.0F && vx_ < target)) {
air_target = vx_; // No frenar el boost
}
if (vx_ < air_target) {
vx_ = std::min(vx_ + STEP, air_target);
} else if (vx_ > air_target) {
vx_ = std::max(vx_ - STEP, air_target);
}
} else {
if (target != 0.0F) {
@@ -212,6 +219,7 @@ void Player::handleJumpAndDrop() {
void Player::startJump() {
vy_ = JUMP_VELOCITY;
vx_ *= JUMP_SPEED_BOOST;
last_grounded_position_ = y_;
Audio::get()->playSound(jump_sound_, Audio::Group::GAME);
transitionToState(State::ON_AIR);
@@ -431,12 +439,17 @@ void Player::transitionToState(State state) {
switch (state) {
case State::ON_GROUND:
vy_ = 0;
// Clamp vx al aterrizar (el salto puede dar un boost extra)
if (vx_ > HORIZONTAL_VELOCITY) { vx_ = HORIZONTAL_VELOCITY; }
if (vx_ < -HORIZONTAL_VELOCITY) { vx_ = -HORIZONTAL_VELOCITY; }
if (previous_state_ == State::ON_AIR) {
Audio::get()->playSound(land_sound_, Audio::Group::GAME);
}
break;
case State::ON_SLOPE:
vy_ = 0;
if (vx_ > HORIZONTAL_VELOCITY) { vx_ = HORIZONTAL_VELOCITY; }
if (vx_ < -HORIZONTAL_VELOCITY) { vx_ = -HORIZONTAL_VELOCITY; }
if (previous_state_ == State::ON_AIR) {
Audio::get()->playSound(land_sound_, Audio::Group::GAME);
}

View File

@@ -37,6 +37,7 @@ class Player {
static constexpr float JUMP_VELOCITY = -178.5F;
static constexpr float GRAVITY_FORCE = 360.0F;
static constexpr float LOW_JUMP_GRAVITY_MULT = 3.0F;
static constexpr float JUMP_SPEED_BOOST = 1.25F;
struct SpawnData {
float x = 0;