forked from jaildesigner-jailgames/jaildoctors_dilemma
fix: al canviar de pantalla lateralment, es resetejava la altura de salt i el jugador caia
This commit is contained in:
@@ -83,8 +83,9 @@ void Player::move(float delta_time) {
|
|||||||
}
|
}
|
||||||
syncSpriteAndCollider(); // Actualiza la posición del sprite y las colisiones
|
syncSpriteAndCollider(); // Actualiza la posición del sprite y las colisiones
|
||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
Debug::get()->add(std::string("X: " + std::to_string(static_cast<int>(x_))));
|
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("Y : " + std::to_string(static_cast<int>(y_))));
|
||||||
|
Debug::get()->add(std::string("LGP: " + std::to_string(static_cast<int>(last_grounded_position_))));
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,22 +111,22 @@ void Player::transitionToState(State state) {
|
|||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case State::ON_GROUND:
|
case State::ON_GROUND:
|
||||||
//std::cout << "ON_GROUND\n";
|
// std::cout << "ON_GROUND\n";
|
||||||
vy_ = 0;
|
vy_ = 0;
|
||||||
handleDeathByFalling();
|
handleDeathByFalling();
|
||||||
resetSoundControllersOnLanding();
|
resetSoundControllersOnLanding();
|
||||||
current_slope_ = nullptr;
|
current_slope_ = nullptr;
|
||||||
break;
|
break;
|
||||||
case State::ON_SLOPE:
|
case State::ON_SLOPE:
|
||||||
//std::cout << "ON_SLOPE\n";
|
// std::cout << "ON_SLOPE\n";
|
||||||
vy_ = 0;
|
vy_ = 0;
|
||||||
handleDeathByFalling();
|
handleDeathByFalling();
|
||||||
resetSoundControllersOnLanding();
|
resetSoundControllersOnLanding();
|
||||||
updateCurrentSlope();
|
updateCurrentSlope();
|
||||||
break;
|
break;
|
||||||
case State::JUMPING:
|
case State::JUMPING:
|
||||||
//std::cout << "JUMPING\n";
|
// std::cout << "JUMPING\n";
|
||||||
// Puede saltar desde ON_GROUND o ON_SLOPE
|
// Puede saltar desde ON_GROUND o ON_SLOPE
|
||||||
if (previous_state_ == State::ON_GROUND || previous_state_ == State::ON_SLOPE) {
|
if (previous_state_ == State::ON_GROUND || previous_state_ == State::ON_SLOPE) {
|
||||||
vy_ = -MAX_VY;
|
vy_ = -MAX_VY;
|
||||||
last_grounded_position_ = y_;
|
last_grounded_position_ = y_;
|
||||||
@@ -135,7 +136,7 @@ void Player::transitionToState(State state) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case State::FALLING:
|
case State::FALLING:
|
||||||
//std::cout << "FALLING\n";
|
// std::cout << "FALLING\n";
|
||||||
fall_start_position_ = static_cast<int>(y_);
|
fall_start_position_ = static_cast<int>(y_);
|
||||||
last_grounded_position_ = static_cast<int>(y_);
|
last_grounded_position_ = static_cast<int>(y_);
|
||||||
vy_ = MAX_VY;
|
vy_ = MAX_VY;
|
||||||
@@ -393,11 +394,15 @@ void Player::switchBorders() {
|
|||||||
switch (border_) {
|
switch (border_) {
|
||||||
case Room::Border::TOP:
|
case Room::Border::TOP:
|
||||||
y_ = PLAY_AREA_BOTTOM - HEIGHT - TILE_SIZE;
|
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
|
transitionToState(State::ON_GROUND); // TODO: Detectar si debe ser ON_SLOPE
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Room::Border::BOTTOM:
|
case Room::Border::BOTTOM:
|
||||||
y_ = PLAY_AREA_TOP;
|
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
|
transitionToState(State::ON_GROUND); // TODO: Detectar si debe ser ON_SLOPE
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -413,8 +418,6 @@ void Player::switchBorders() {
|
|||||||
break;
|
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;
|
is_on_border_ = false;
|
||||||
placeSprite();
|
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)
|
// Reproduce si hemos avanzado a un nuevo índice (permite repetición de sonido 13)
|
||||||
if (target_index > current_index) {
|
if (target_index > current_index) {
|
||||||
current_index = target_index; // Guardamos el índice real (puede ser > LAST_SOUND)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user