modernitzat el canvi de pantalla

This commit is contained in:
2026-04-06 17:55:20 +02:00
parent 8f6b5f7cac
commit 42c5bcadf5

View File

@@ -359,51 +359,50 @@ void Player::moveOnAir(float delta_time) {
}
}
// Comprueba si está situado en alguno de los cuatro bordes de la habitación
// Comprueba si el punto central del jugador ha sobrepasado alguno de los bordes
auto Player::handleBorders() -> Room::Border {
if (x_ < PlayArea::LEFT) {
const float CENTER_X = x_ + WIDTH / 2.0F;
const float CENTER_Y = y_ + HEIGHT / 2.0F;
if (CENTER_X < PlayArea::LEFT) {
return Room::Border::LEFT;
}
if (x_ + WIDTH > PlayArea::RIGHT) {
if (CENTER_X > PlayArea::RIGHT) {
return Room::Border::RIGHT;
}
if (y_ < PlayArea::TOP) {
if (CENTER_Y < PlayArea::TOP) {
return Room::Border::TOP;
}
if (y_ + HEIGHT > PlayArea::BOTTOM) {
// Restricción de muerte por altura de caída desactivada
if (CENTER_Y > PlayArea::BOTTOM) {
return Room::Border::BOTTOM;
}
return Room::Border::NONE;
}
// Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla
// Cambia al jugador de un borde al opuesto conservando velocidad y estado.
// Usa el punto central para calcular la posición en la pantalla destino.
void Player::switchBorders() {
switch (border_) {
case Room::Border::TOP:
y_ = PlayArea::BOTTOM - HEIGHT - Tile::SIZE;
// CRÍTICO: Resetear last_grounded_position_ para evitar muerte falsa por diferencia de Y entre pantallas
y_ += PlayArea::HEIGHT;
last_grounded_position_ = static_cast<int>(y_);
transitionToState(State::ON_GROUND); // TODO: Detectar si debe ser ON_SLOPE
break;
case Room::Border::BOTTOM:
y_ = PlayArea::TOP;
// CRÍTICO: Resetear last_grounded_position_ para evitar muerte falsa por diferencia de Y entre pantallas
y_ -= PlayArea::HEIGHT;
last_grounded_position_ = static_cast<int>(y_);
transitionToState(State::ON_GROUND); // TODO: Detectar si debe ser ON_SLOPE
break;
case Room::Border::RIGHT:
x_ = PlayArea::LEFT;
x_ -= PlayArea::WIDTH;
break;
case Room::Border::LEFT:
x_ = PlayArea::RIGHT - WIDTH;
x_ += PlayArea::WIDTH;
break;
default: