fix: bug mileanri que deixava al jugador atascat en algunes rampes en certes condicions

This commit is contained in:
2026-03-28 22:22:32 +01:00
parent 9282d661aa
commit 6717c1e307
2 changed files with 10 additions and 4 deletions

View File

@@ -136,6 +136,10 @@ void Player::transitionToState(State state) {
handleDeathByFalling(); handleDeathByFalling();
resetSoundControllersOnLanding(); resetSoundControllersOnLanding();
updateCurrentSlope(); updateCurrentSlope();
if (current_slope_ == nullptr) {
// Los pies no coinciden con ninguna rampa: tratar como suelo plano
state_ = State::ON_GROUND;
}
break; break;
case State::JUMPING: case State::JUMPING:
// Puede saltar desde ON_GROUND o ON_SLOPE // Puede saltar desde ON_GROUND o ON_SLOPE
@@ -248,14 +252,15 @@ void Player::moveOnSlope(float delta_time) {
// Determinama cuál debe ser la velocidad a partir de automovement o de wanna_go_ // Determinama cuál debe ser la velocidad a partir de automovement o de wanna_go_
updateVelocity(); updateVelocity();
if (vx_ == 0.0F) { return; } // 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)
// Verificar que tenemos una rampa válida
if (current_slope_ == nullptr) { if (current_slope_ == nullptr) {
transitionToState(State::FALLING); transitionToState(State::FALLING);
return; return;
} }
if (vx_ == 0.0F) { return; }
// Determinar el tipo de rampa // Determinar el tipo de rampa
const bool IS_LEFT_SLOPE = isLeftSlope(); const bool IS_LEFT_SLOPE = isLeftSlope();
@@ -588,6 +593,7 @@ void Player::updateCurrentSlope() {
} }
} }
#ifdef _DEBUG #ifdef _DEBUG
if (current_slope_ != nullptr) { if (current_slope_ != nullptr) {
Debug::get()->set("sl.type", isLeftSlope() ? "L\\" : "R/"); Debug::get()->set("sl.type", isLeftSlope() ? "L\\" : "R/");

View File

@@ -262,7 +262,7 @@ auto checkCollision(const LineDiagonal& l1, const LineVertical& l2) -> SDL_Point
const float X = X1 + (u_a * (X2 - X1)); const float X = X1 + (u_a * (X2 - X1));
const float Y = Y1 + (u_a * (Y2 - Y1)); const float Y = Y1 + (u_a * (Y2 - Y1));
return {.x = static_cast<int>(X), .y = static_cast<int>(Y)}; return {.x = static_cast<int>(std::round(X)), .y = static_cast<int>(std::round(Y))};
} }
return {.x = -1, .y = -1}; return {.x = -1, .y = -1};
} }