fix: al canviar de pantalla lateralment, es resetejava la altura de salt i el jugador caia

This commit is contained in:
2025-11-19 22:52:31 +01:00
parent 28f11a42b7
commit 7d962ae752

View File

@@ -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<int>(x_))));
Debug::get()->add(std::string("Y: " + std::to_string(static_cast<int>(y_))));
Debug::get()->add(std::string("X : " + std::to_string(static_cast<int>(x_))));
Debug::get()->add(std::string("Y : " + std::to_string(static_cast<int>(y_))));
Debug::get()->add(std::string("LGP: " + std::to_string(static_cast<int>(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<int>(y_);
last_grounded_position_ = static_cast<int>(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<int>(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<int>(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<int>(y_);
is_on_border_ = false;
placeSprite();
}
@@ -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;
}