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 { 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; return Room::Border::LEFT;
} }
if (x_ + WIDTH > PlayArea::RIGHT) { if (CENTER_X > PlayArea::RIGHT) {
return Room::Border::RIGHT; return Room::Border::RIGHT;
} }
if (y_ < PlayArea::TOP) { if (CENTER_Y < PlayArea::TOP) {
return Room::Border::TOP; return Room::Border::TOP;
} }
if (y_ + HEIGHT > PlayArea::BOTTOM) { if (CENTER_Y > PlayArea::BOTTOM) {
// Restricción de muerte por altura de caída desactivada
return Room::Border::BOTTOM; return Room::Border::BOTTOM;
} }
return Room::Border::NONE; 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() { void Player::switchBorders() {
switch (border_) { switch (border_) {
case Room::Border::TOP: case Room::Border::TOP:
y_ = PlayArea::BOTTOM - HEIGHT - Tile::SIZE; y_ += PlayArea::HEIGHT;
// CRÍTICO: Resetear last_grounded_position_ para evitar muerte falsa por diferencia de Y entre pantallas
last_grounded_position_ = static_cast<int>(y_); last_grounded_position_ = static_cast<int>(y_);
transitionToState(State::ON_GROUND); // TODO: Detectar si debe ser ON_SLOPE
break; break;
case Room::Border::BOTTOM: case Room::Border::BOTTOM:
y_ = PlayArea::TOP; y_ -= PlayArea::HEIGHT;
// CRÍTICO: Resetear last_grounded_position_ para evitar muerte falsa por diferencia de Y entre pantallas
last_grounded_position_ = static_cast<int>(y_); last_grounded_position_ = static_cast<int>(y_);
transitionToState(State::ON_GROUND); // TODO: Detectar si debe ser ON_SLOPE
break; break;
case Room::Border::RIGHT: case Room::Border::RIGHT:
x_ = PlayArea::LEFT; x_ -= PlayArea::WIDTH;
break; break;
case Room::Border::LEFT: case Room::Border::LEFT:
x_ = PlayArea::RIGHT - WIDTH; x_ += PlayArea::WIDTH;
break; break;
default: default: