This commit is contained in:
2026-04-07 13:42:06 +02:00
parent a50223fcd7
commit 60a074167f

View File

@@ -479,15 +479,15 @@ void Game::renderPlaying() {
player_->render(); player_->render();
} }
// Renderizar habitación adyacente desplazada // Renderizar habitación adyacente: misma cámara pero desplazada una pantalla
if (transition_adjacent_room_) { if (transition_adjacent_room_) {
int adj_x = cam_x; int adj_x = cam_x;
int adj_y = cam_y; int adj_y = cam_y;
switch (transition_direction_) { switch (transition_direction_) {
case Room::Border::TOP: adj_y -= PlayArea::HEIGHT; break; case Room::Border::TOP: adj_y += -PlayArea::HEIGHT; break;
case Room::Border::BOTTOM: adj_y += PlayArea::HEIGHT; break; case Room::Border::BOTTOM: adj_y += PlayArea::HEIGHT; break;
case Room::Border::LEFT: adj_x -= PlayArea::WIDTH; break; case Room::Border::LEFT: adj_x += -PlayArea::WIDTH; break;
case Room::Border::RIGHT: adj_x += PlayArea::WIDTH; break; case Room::Border::RIGHT: adj_x += PlayArea::WIDTH; break;
default: break; default: break;
} }
Screen::get()->setRenderOffset(adj_x, adj_y); Screen::get()->setRenderOffset(adj_x, adj_y);
@@ -851,27 +851,29 @@ void Game::checkPlayerIsOnBorder() {
// Actualiza la cámara durante la transición: sigue al jugador con inercia // Actualiza la cámara durante la transición: sigue al jugador con inercia
void Game::updateTransitionCamera(float delta_time) { void Game::updateTransitionCamera(float delta_time) {
// Calcular el offset objetivo basado en la posición del jugador // El target es una pantalla completa en la dirección de la transición,
// excepto si el jugador ha vuelto dentro de bounds (target = 0)
float target_x = 0.0F; float target_x = 0.0F;
float target_y = 0.0F; float target_y = 0.0F;
const auto RECT = player_->getRect(); const auto RECT = player_->getRect();
const float CENTER_X = RECT.x + (RECT.w / 2.0F); const float CENTER_X = RECT.x + (RECT.w / 2.0F);
const float CENTER_Y = RECT.y + (RECT.h / 2.0F); const float CENTER_Y = RECT.y + (RECT.h / 2.0F);
const bool PLAYER_OUT_OF_BOUNDS =
CENTER_X < PlayArea::LEFT || CENTER_X > PlayArea::RIGHT ||
CENTER_Y < PlayArea::TOP || CENTER_Y > PlayArea::BOTTOM;
if (transition_direction_ == Room::Border::TOP || transition_direction_ == Room::Border::BOTTOM) { if (PLAYER_OUT_OF_BOUNDS) {
if (CENTER_Y < PlayArea::TOP) { // El jugador está fuera: la cámara se dirige a mostrar la room adyacente
target_y = static_cast<float>(PlayArea::HEIGHT); switch (transition_direction_) {
} else if (CENTER_Y > PlayArea::BOTTOM) { case Room::Border::TOP: target_y = static_cast<float>(PlayArea::HEIGHT); break;
target_y = -static_cast<float>(PlayArea::HEIGHT); case Room::Border::BOTTOM: target_y = -static_cast<float>(PlayArea::HEIGHT); break;
} case Room::Border::LEFT: target_x = static_cast<float>(PlayArea::WIDTH); break;
} else if (transition_direction_ == Room::Border::LEFT || transition_direction_ == Room::Border::RIGHT) { case Room::Border::RIGHT: target_x = -static_cast<float>(PlayArea::WIDTH); break;
if (CENTER_X < PlayArea::LEFT) { default: break;
target_x = static_cast<float>(PlayArea::WIDTH);
} else if (CENTER_X > PlayArea::RIGHT) {
target_x = -static_cast<float>(PlayArea::WIDTH);
} }
} }
// Si el jugador está dentro de bounds, target = 0 → la cámara vuelve
// Interpolar la cámara hacia el objetivo con velocidad constante // Interpolar la cámara hacia el objetivo con velocidad constante
constexpr float CAMERA_SPEED = 500.0F; constexpr float CAMERA_SPEED = 500.0F;