From 60a074167fa8afc395be3669db988c1a24fa54f5 Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 7 Apr 2026 13:42:06 +0200 Subject: [PATCH] proves2 --- source/game/scenes/game.cpp | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/source/game/scenes/game.cpp b/source/game/scenes/game.cpp index 961f551..76e15d4 100644 --- a/source/game/scenes/game.cpp +++ b/source/game/scenes/game.cpp @@ -479,15 +479,15 @@ void Game::renderPlaying() { player_->render(); } - // Renderizar habitación adyacente desplazada + // Renderizar habitación adyacente: misma cámara pero desplazada una pantalla if (transition_adjacent_room_) { int adj_x = cam_x; int adj_y = cam_y; switch (transition_direction_) { - case Room::Border::TOP: 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::RIGHT: adj_x += PlayArea::WIDTH; break; + case Room::Border::TOP: 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::RIGHT: adj_x += PlayArea::WIDTH; break; default: break; } 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 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_y = 0.0F; const auto RECT = player_->getRect(); const float CENTER_X = RECT.x + (RECT.w / 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 (CENTER_Y < PlayArea::TOP) { - target_y = static_cast(PlayArea::HEIGHT); - } else if (CENTER_Y > PlayArea::BOTTOM) { - target_y = -static_cast(PlayArea::HEIGHT); - } - } else if (transition_direction_ == Room::Border::LEFT || transition_direction_ == Room::Border::RIGHT) { - if (CENTER_X < PlayArea::LEFT) { - target_x = static_cast(PlayArea::WIDTH); - } else if (CENTER_X > PlayArea::RIGHT) { - target_x = -static_cast(PlayArea::WIDTH); + if (PLAYER_OUT_OF_BOUNDS) { + // El jugador está fuera: la cámara se dirige a mostrar la room adyacente + switch (transition_direction_) { + case Room::Border::TOP: target_y = static_cast(PlayArea::HEIGHT); break; + case Room::Border::BOTTOM: target_y = -static_cast(PlayArea::HEIGHT); break; + case Room::Border::LEFT: target_x = static_cast(PlayArea::WIDTH); break; + case Room::Border::RIGHT: target_x = -static_cast(PlayArea::WIDTH); break; + default: break; } } + // Si el jugador está dentro de bounds, target = 0 → la cámara vuelve // Interpolar la cámara hacia el objetivo con velocidad constante constexpr float CAMERA_SPEED = 500.0F;