marcador provisional

This commit is contained in:
2026-04-06 14:53:58 +02:00
parent 67bf6b2017
commit 4c5e1e5470
12 changed files with 180 additions and 181 deletions

View File

@@ -414,9 +414,12 @@ void Player::switchBorders() {
// Aplica gravedad al jugador
void Player::applyGravity(float delta_time) {
// La gravedad solo se aplica cuando el jugador esta en el aire
if (state_ == State::ON_AIR) {
vy_ += GRAVITY_FORCE * delta_time;
// Si está subiendo y ha soltado el botón de salto, gravedad aumentada para cortar el salto
const float GRAVITY = (vy_ < 0.0F && !wanna_jump_)
? GRAVITY_FORCE * LOW_JUMP_GRAVITY_MULT
: GRAVITY_FORCE;
vy_ += GRAVITY * delta_time;
vy_ = std::min(vy_, MAX_VY);
}
}
@@ -675,12 +678,16 @@ void Player::updateVelocity(float delta_time) {
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);
// En el aire: inercia (interpolación gradual). En suelo/rampa: respuesta inmediata.
if (state_ == State::ON_AIR) {
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);
}
} else {
vx_ = target;
}
}

View File

@@ -38,6 +38,7 @@ class Player {
static constexpr float MAX_VY = 160.0F; // Velocidad vertical máxima en pixels/segundo
static constexpr float JUMP_VELOCITY = -140.0F; // Velocidad inicial del salto en pixels/segundo
static constexpr float GRAVITY_FORCE = 360.0F; // Fuerza de gravedad en pixels/segundo²
static constexpr float LOW_JUMP_GRAVITY_MULT = 3.0F; // Multiplicador de gravedad al soltar el botón de salto (salto variable)
struct SpawnData {
float x = 0;