From 42c5bcadf553ffd021c55f1bb3fb3a9fda3eed46 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Mon, 6 Apr 2026 17:55:20 +0200 Subject: [PATCH] modernitzat el canvi de pantalla --- source/game/entities/player.cpp | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/source/game/entities/player.cpp b/source/game/entities/player.cpp index 4ecd0b7..6558ced 100644 --- a/source/game/entities/player.cpp +++ b/source/game/entities/player.cpp @@ -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(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(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: