From 2a63227ee2224fb7b2afb4085beea9df186fd3d3 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 8 Apr 2026 18:09:41 +0200 Subject: [PATCH] stule: el jugador no gira el sprite en el aire --- source/game/entities/player.cpp | 33 +++++++++++++++++++++++---------- source/game/entities/player.hpp | 1 + 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index 55e3f27..88fddc2 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -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); } diff --git a/source/game/entities/player.hpp b/source/game/entities/player.hpp index c40da55..2743b36 100644 --- a/source/game/entities/player.hpp +++ b/source/game/entities/player.hpp @@ -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;