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

View File

@@ -479,14 +479,14 @@ 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::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::LEFT: adj_x += -PlayArea::WIDTH; break;
case Room::Border::RIGHT: adj_x += PlayArea::WIDTH; break;
default: break;
}
@@ -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<float>(PlayArea::HEIGHT);
} else if (CENTER_Y > PlayArea::BOTTOM) {
target_y = -static_cast<float>(PlayArea::HEIGHT);
}
} else if (transition_direction_ == Room::Border::LEFT || transition_direction_ == Room::Border::RIGHT) {
if (CENTER_X < PlayArea::LEFT) {
target_x = static_cast<float>(PlayArea::WIDTH);
} else if (CENTER_X > PlayArea::RIGHT) {
target_x = -static_cast<float>(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<float>(PlayArea::HEIGHT); break;
case Room::Border::BOTTOM: target_y = -static_cast<float>(PlayArea::HEIGHT); break;
case Room::Border::LEFT: target_x = static_cast<float>(PlayArea::WIDTH); break;
case Room::Border::RIGHT: target_x = -static_cast<float>(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;