Implementar modo real fullscreen y resolver conflictos

MODO REAL FULLSCREEN (F4):
- F4: Cambia resolución interna a resolución nativa del escritorio
- Pelotas usan dimensiones dinámicas del terreno de juego
- Interfaz se adapta automáticamente (texto, debug, gradiente)
- Reinicio automático de escena con nuevas dimensiones

RESOLUCIÓN DINÁMICA:
- Ball constructor acepta screen_width/height como parámetros
- Colisiones usan dimensiones dinámicas en lugar de constantes
- Spawn de pelotas usa margen configurable (BALL_SPAWN_MARGIN)
- Toda la interfaz se adapta a resolución actual

MODOS FULLSCREEN MUTUAMENTE EXCLUYENTES:
- F3 (fullscreen normal) y F4 (real fullscreen) se desactivan mutuamente
- F1/F2 (zoom) bloqueados durante cualquier modo fullscreen
- Sin estados mixtos que rompan el renderizado
- Transiciones seguras entre todos los modos

MEJORAS DE CONFIGURACIÓN:
- BALL_SPAWN_MARGIN: margen lateral configurable para spawn de pelotas
- Resolución base actualizada a 640x360 (16:9)
- Spawn margin reducido a 15% para mayor dispersión

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-18 19:20:02 +02:00
parent 9908165104
commit 7b24e387b7
5 changed files with 117 additions and 38 deletions

View File

@@ -264,19 +264,28 @@ void Engine::handleEvents() {
initBalls(scenario_);
break;
// Controles de zoom dinámico
// Controles de zoom dinámico (solo si no estamos en fullscreen)
case SDLK_F1:
zoomOut();
if (!fullscreen_enabled_ && !real_fullscreen_enabled_) {
zoomOut();
}
break;
case SDLK_F2:
zoomIn();
if (!fullscreen_enabled_ && !real_fullscreen_enabled_) {
zoomIn();
}
break;
// Control de pantalla completa
case SDLK_F3:
toggleFullscreen();
break;
// Modo real fullscreen (cambia resolución interna)
case SDLK_F4:
toggleRealFullscreen();
break;
}
}
}
@@ -310,7 +319,7 @@ void Engine::render() {
std::string theme_names_es[] = {"ATARDECER", "OCEANO", "NEON", "BOSQUE"};
std::string theme_name = theme_names_es[static_cast<int>(current_theme_)];
int theme_text_width = static_cast<int>(theme_name.length() * 8); // 8 píxeles por carácter
int theme_x = (SCREEN_WIDTH - theme_text_width) / 2; // Centrar horizontalmente
int theme_x = (current_screen_width_ - theme_text_width) / 2; // Centrar horizontalmente
// Colores acordes a cada tema
int theme_colors[][3] = {
@@ -327,7 +336,7 @@ void Engine::render() {
if (show_debug_) {
// Mostrar contador de FPS en esquina superior derecha
int fps_text_width = static_cast<int>(fps_text_.length() * 8); // 8 píxeles por carácter
int fps_x = SCREEN_WIDTH - fps_text_width - 8; // 8 píxeles de margen
int fps_x = current_screen_width_ - fps_text_width - 8; // 8 píxeles de margen
dbg_print(fps_x, 8, fps_text_.c_str(), 255, 255, 0); // Amarillo para distinguir
// Mostrar estado V-Sync en esquina superior izquierda
@@ -378,7 +387,10 @@ void Engine::initBalls(int value) {
// Crear las bolas según el escenario
for (int i = 0; i < test_.at(value); ++i) {
const int SIGN = ((rand() % 2) * 2) - 1; // Genera un signo aleatorio (+ o -)
const float X = (rand() % (SCREEN_WIDTH / 2)) + (SCREEN_WIDTH / 4); // Posición inicial en X
// Calcular spawn zone: margen a cada lado, zona central para spawn
const int margin = static_cast<int>(current_screen_width_ * BALL_SPAWN_MARGIN);
const int spawn_zone_width = current_screen_width_ - (2 * margin);
const float X = (rand() % spawn_zone_width) + margin; // Posición inicial en X
const float VX = (((rand() % 20) + 10) * 0.1f) * SIGN; // Velocidad en X
const float VY = ((rand() % 60) - 30) * 0.1f; // Velocidad en Y
// Seleccionar color de la paleta del tema actual
@@ -389,7 +401,7 @@ void Engine::initBalls(int value) {
theme.ball_colors[color_index][2]};
// Generar factor de masa aleatorio (0.7 = ligera, 1.3 = pesada)
float mass_factor = GRAVITY_MASS_MIN + (rand() % 1000) / 1000.0f * (GRAVITY_MASS_MAX - GRAVITY_MASS_MIN);
balls_.emplace_back(std::make_unique<Ball>(X, VX, VY, COLOR, texture_, current_gravity_, mass_factor));
balls_.emplace_back(std::make_unique<Ball>(X, VX, VY, COLOR, texture_, current_screen_width_, current_screen_height_, current_gravity_, mass_factor));
}
setText(); // Actualiza el texto
}
@@ -401,7 +413,7 @@ void Engine::setText() {
} else {
text_ = std::to_string(num_balls) + " PELOTAS";
}
text_pos_ = (SCREEN_WIDTH - static_cast<int>(text_.length() * 8)) / 2; // Centrar texto
text_pos_ = (current_screen_width_ - static_cast<int>(text_.length() * 8)) / 2; // Centrar texto
show_text_ = true;
text_init_time_ = SDL_GetTicks();
}
@@ -438,10 +450,64 @@ void Engine::toggleVSync() {
}
void Engine::toggleFullscreen() {
// Si está en modo real fullscreen, primero salir de él
if (real_fullscreen_enabled_) {
toggleRealFullscreen(); // Esto lo desactiva
}
fullscreen_enabled_ = !fullscreen_enabled_;
SDL_SetWindowFullscreen(window_, fullscreen_enabled_);
}
void Engine::toggleRealFullscreen() {
// Si está en modo fullscreen normal, primero desactivarlo
if (fullscreen_enabled_) {
fullscreen_enabled_ = false;
SDL_SetWindowFullscreen(window_, false);
}
real_fullscreen_enabled_ = !real_fullscreen_enabled_;
if (real_fullscreen_enabled_) {
// Obtener resolución del escritorio
int num_displays = 0;
SDL_DisplayID *displays = SDL_GetDisplays(&num_displays);
if (displays != nullptr && num_displays > 0) {
const auto *dm = SDL_GetCurrentDisplayMode(displays[0]);
if (dm != nullptr) {
// Cambiar a resolución nativa del escritorio
current_screen_width_ = dm->w;
current_screen_height_ = dm->h;
// Recrear ventana con nueva resolución
SDL_SetWindowSize(window_, current_screen_width_, current_screen_height_);
SDL_SetWindowFullscreen(window_, true);
// Actualizar presentación lógica del renderizador
SDL_SetRenderLogicalPresentation(renderer_, current_screen_width_, current_screen_height_, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
// Reinicar la escena con nueva resolución
initBalls(scenario_);
}
SDL_free(displays);
}
} else {
// Volver a resolución original
current_screen_width_ = SCREEN_WIDTH;
current_screen_height_ = SCREEN_HEIGHT;
// Restaurar ventana normal
SDL_SetWindowFullscreen(window_, false);
SDL_SetWindowSize(window_, SCREEN_WIDTH * WINDOW_ZOOM, SCREEN_HEIGHT * WINDOW_ZOOM);
// Restaurar presentación lógica original
SDL_SetRenderLogicalPresentation(renderer_, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE);
// Reinicar la escena con resolución original
initBalls(scenario_);
}
}
std::string Engine::gravityDirectionToString(GravityDirection direction) const {
switch (direction) {
case GravityDirection::DOWN: return "DOWN";
@@ -473,17 +539,17 @@ void Engine::renderGradientBackground() {
bg_vertices[0].color = {top_r, top_g, top_b, 1.0f};
// Vértice superior derecho
bg_vertices[1].position = {SCREEN_WIDTH, 0};
bg_vertices[1].position = {static_cast<float>(current_screen_width_), 0};
bg_vertices[1].tex_coord = {1.0f, 0.0f};
bg_vertices[1].color = {top_r, top_g, top_b, 1.0f};
// Vértice inferior derecho
bg_vertices[2].position = {SCREEN_WIDTH, SCREEN_HEIGHT};
bg_vertices[2].position = {static_cast<float>(current_screen_width_), static_cast<float>(current_screen_height_)};
bg_vertices[2].tex_coord = {1.0f, 1.0f};
bg_vertices[2].color = {bottom_r, bottom_g, bottom_b, 1.0f};
// Vértice inferior izquierdo
bg_vertices[3].position = {0, SCREEN_HEIGHT};
bg_vertices[3].position = {0, static_cast<float>(current_screen_height_)};
bg_vertices[3].tex_coord = {0.0f, 1.0f};
bg_vertices[3].color = {bottom_r, bottom_g, bottom_b, 1.0f};