From 6717c1e30714dde7e8797ccb322fb6990487e199 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sat, 28 Mar 2026 22:22:32 +0100 Subject: [PATCH] fix: bug mileanri que deixava al jugador atascat en algunes rampes en certes condicions --- source/game/entities/player.cpp | 12 +++++++++--- source/utils/utils.cpp | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index b8c79ac..c430479 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -136,6 +136,10 @@ void Player::transitionToState(State state) { handleDeathByFalling(); resetSoundControllersOnLanding(); updateCurrentSlope(); + if (current_slope_ == nullptr) { + // Los pies no coinciden con ninguna rampa: tratar como suelo plano + state_ = State::ON_GROUND; + } break; case State::JUMPING: // 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_ updateVelocity(); - if (vx_ == 0.0F) { return; } - - // Verificar que tenemos una rampa válida + // 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) if (current_slope_ == nullptr) { transitionToState(State::FALLING); return; } + if (vx_ == 0.0F) { return; } + // Determinar el tipo de rampa const bool IS_LEFT_SLOPE = isLeftSlope(); @@ -588,6 +593,7 @@ void Player::updateCurrentSlope() { } } + #ifdef _DEBUG if (current_slope_ != nullptr) { Debug::get()->set("sl.type", isLeftSlope() ? "L\\" : "R/"); diff --git a/source/utils/utils.cpp b/source/utils/utils.cpp index f9ff02d..325f548 100644 --- a/source/utils/utils.cpp +++ b/source/utils/utils.cpp @@ -262,7 +262,7 @@ auto checkCollision(const LineDiagonal& l1, const LineVertical& l2) -> SDL_Point const float X = X1 + (u_a * (X2 - X1)); const float Y = Y1 + (u_a * (Y2 - Y1)); - return {.x = static_cast(X), .y = static_cast(Y)}; + return {.x = static_cast(std::round(X)), .y = static_cast(std::round(Y))}; } return {.x = -1, .y = -1}; }