From 7d962ae752bae19698c969d1e41731af5460033f Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Wed, 19 Nov 2025 22:52:31 +0100 Subject: [PATCH] fix: al canviar de pantalla lateralment, es resetejava la altura de salt i el jugador caia --- source/game/entities/player.cpp | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index a2faae7..fcf4e8b 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -83,8 +83,9 @@ void Player::move(float delta_time) { } syncSpriteAndCollider(); // Actualiza la posición del sprite y las colisiones #ifdef _DEBUG - Debug::get()->add(std::string("X: " + std::to_string(static_cast(x_)))); - Debug::get()->add(std::string("Y: " + std::to_string(static_cast(y_)))); + Debug::get()->add(std::string("X : " + std::to_string(static_cast(x_)))); + Debug::get()->add(std::string("Y : " + std::to_string(static_cast(y_)))); + Debug::get()->add(std::string("LGP: " + std::to_string(static_cast(last_grounded_position_)))); #endif } @@ -110,22 +111,22 @@ void Player::transitionToState(State state) { switch (state) { case State::ON_GROUND: - //std::cout << "ON_GROUND\n"; + // std::cout << "ON_GROUND\n"; vy_ = 0; handleDeathByFalling(); resetSoundControllersOnLanding(); current_slope_ = nullptr; break; case State::ON_SLOPE: - //std::cout << "ON_SLOPE\n"; + // std::cout << "ON_SLOPE\n"; vy_ = 0; handleDeathByFalling(); resetSoundControllersOnLanding(); updateCurrentSlope(); break; case State::JUMPING: - //std::cout << "JUMPING\n"; - // Puede saltar desde ON_GROUND o ON_SLOPE + // std::cout << "JUMPING\n"; + // Puede saltar desde ON_GROUND o ON_SLOPE if (previous_state_ == State::ON_GROUND || previous_state_ == State::ON_SLOPE) { vy_ = -MAX_VY; last_grounded_position_ = y_; @@ -135,7 +136,7 @@ void Player::transitionToState(State state) { } break; case State::FALLING: - //std::cout << "FALLING\n"; + // std::cout << "FALLING\n"; fall_start_position_ = static_cast(y_); last_grounded_position_ = static_cast(y_); vy_ = MAX_VY; @@ -393,11 +394,15 @@ void Player::switchBorders() { switch (border_) { case Room::Border::TOP: y_ = PLAY_AREA_BOTTOM - HEIGHT - TILE_SIZE; + // CRÍTICO: Resetear last_grounded_position_ para evitar muerte falsa por diferencia de Y entre pantallas + last_grounded_position_ = static_cast(y_); transitionToState(State::ON_GROUND); // TODO: Detectar si debe ser ON_SLOPE break; case Room::Border::BOTTOM: y_ = PLAY_AREA_TOP; + // CRÍTICO: Resetear last_grounded_position_ para evitar muerte falsa por diferencia de Y entre pantallas + last_grounded_position_ = static_cast(y_); transitionToState(State::ON_GROUND); // TODO: Detectar si debe ser ON_SLOPE break; @@ -413,8 +418,6 @@ void Player::switchBorders() { break; } - // CRÍTICO: Resetear last_grounded_position_ para evitar muerte falsa por diferencia de Y entre pantallas - last_grounded_position_ = static_cast(y_); is_on_border_ = false; placeSprite(); } @@ -568,7 +571,7 @@ void Player::updateCurrentSlope() { std::cout << "[SLOPE] " << TYPE << " from (" << current_slope_->x1 << "," << current_slope_->y1 << ")" << " to (" << current_slope_->x2 << "," << current_slope_->y2 << ")\n"; - + } else { std::cout << "[SLOPE] nullptr\n"; } @@ -709,7 +712,7 @@ auto Player::FallSoundController::shouldPlay(float delta_time, float current_y, // Reproduce si hemos avanzado a un nuevo índice (permite repetición de sonido 13) if (target_index > current_index) { current_index = target_index; // Guardamos el índice real (puede ser > LAST_SOUND) - out_index = sound_to_play; // Pero reproducimos LAST_SOUND cuando corresponde + out_index = sound_to_play; // Pero reproducimos LAST_SOUND cuando corresponde return true; }