neteja tidy (29 → 0) i migració JA_* → Ja::

This commit is contained in:
2026-05-16 18:40:00 +02:00
parent 75fd037251
commit d1cf6f5529
22 changed files with 798 additions and 745 deletions
+61 -47
View File
@@ -156,71 +156,85 @@ void Player::handleInput() {
// Fase 2: Velocidades
// ============================================================================
void Player::updateVelocity(float delta_time) {
float target = 0.0F;
auto Player::computeHorizontalTarget() const -> float {
switch (wanna_go_) {
case Direction::LEFT:
target = -HORIZONTAL_VELOCITY;
break;
return -HORIZONTAL_VELOCITY;
case Direction::RIGHT:
target = HORIZONTAL_VELOCITY;
break;
return HORIZONTAL_VELOCITY;
default:
target = 0.0F;
break;
return 0.0F;
}
}
void Player::updateFacing(float target) {
if (state_ == State::ON_AIR) { return; }
// 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_) {
facing_ = new_facing;
if (target != 0.0F) {
const Direction NEW_FACING = (target > 0.0F) ? Direction::RIGHT : Direction::LEFT;
if (NEW_FACING != facing_) {
facing_ = NEW_FACING;
turning_ = true;
sprite_->resetAnimation();
}
}
// 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);
}
// Orientación del sprite
if (target > 0.0F) {
sprite_->setFlip(Flip::RIGHT);
} else if (target < 0.0F) {
sprite_->setFlip(Flip::LEFT);
}
}
void Player::applyAirInertia(float target, float step) {
// 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_;
}
if (vx_ < air_target) {
vx_ = std::min(vx_ + step, air_target);
} else if (vx_ > air_target) {
vx_ = std::max(vx_ - step, air_target);
}
}
void Player::applyGroundInertia(float target, float step, float delta_time) {
if (target != 0.0F) {
// Reset al cambiar de dirección: un giro breve también para en seco.
if (vx_ != 0.0F && ((target > 0.0F) != (vx_ > 0.0F))) {
walk_time_ = 0.0F;
}
vx_ = target;
walk_time_ += delta_time;
return;
}
if (walk_time_ < WALK_INERTIA_THRESHOLD) {
// Tap corto: parada seca, sin inercia (permite pasos finos).
vx_ = 0.0F;
walk_time_ = 0.0F;
return;
}
if (vx_ > 0.0F) {
vx_ = std::max(vx_ - step, 0.0F);
} else if (vx_ < 0.0F) {
vx_ = std::min(vx_ + step, 0.0F);
}
if (vx_ == 0.0F) { walk_time_ = 0.0F; }
}
void Player::updateVelocity(float delta_time) {
const float TARGET = computeHorizontalTarget();
updateFacing(TARGET);
// Inercia: aire = gradual ambas direcciones, suelo = instantáneo arranque, gradual frenada
const float STEP = HORIZONTAL_ACCEL * delta_time;
if (state_ == State::ON_AIR) {
// 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);
}
applyAirInertia(TARGET, STEP);
} else {
if (target != 0.0F) {
// Reset al cambiar de dirección: un giro breve también para en seco.
if (vx_ != 0.0F && ((target > 0.0F) != (vx_ > 0.0F))) {
walk_time_ = 0.0F;
}
vx_ = target;
walk_time_ += delta_time;
} else if (walk_time_ < WALK_INERTIA_THRESHOLD) {
// Tap corto: parada seca, sin inercia (permite pasos finos).
vx_ = 0.0F;
walk_time_ = 0.0F;
} else if (vx_ > 0.0F) {
vx_ = std::max(vx_ - STEP, 0.0F);
if (vx_ == 0.0F) { walk_time_ = 0.0F; }
} else if (vx_ < 0.0F) {
vx_ = std::min(vx_ + STEP, 0.0F);
if (vx_ == 0.0F) { walk_time_ = 0.0F; }
}
applyGroundInertia(TARGET, STEP, delta_time);
}
}