corregits bugs dels sub-bucles aplanats

- Demo ja no entra en pausa ni game over (redirigeix a instruccions)
- Perdre el focus de la finestra només pausa durant el joc actiu (no en demo, game over ni pausa)
- Demo gestionat amb save/restore de section->name per evitar transició del Director

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 19:45:39 +02:00
parent 06d4712493
commit 85a47c1a2b
2 changed files with 21 additions and 2 deletions

View File

@@ -2944,6 +2944,15 @@ bool Game::isDeathShaking() {
// Ejecuta un frame del juego
void Game::iterate() {
// En modo demo, no hay pausa ni game over
if (demo.enabled) {
if (section->subsection == SUBSECTION_GAME_PAUSE || section->subsection == SUBSECTION_GAME_GAMEOVER) {
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_INSTRUCTIONS;
return;
}
}
// Sección juego en pausa
if (section->subsection == SUBSECTION_GAME_PAUSE) {
if (!pauseInitialized) {
@@ -3001,8 +3010,11 @@ void Game::handleEvent(SDL_Event *event) {
// SDL_EVENT_QUIT ya lo maneja Director
if (event->type == SDL_EVENT_WINDOW_FOCUS_LOST) {
// Solo pausar durante el juego activo (no en demo, game over, ni ya en pausa)
if (!demo.enabled && (section->subsection == SUBSECTION_GAME_PLAY_1P || section->subsection == SUBSECTION_GAME_PLAY_2P)) {
section->subsection = SUBSECTION_GAME_PAUSE;
}
}
#ifdef PAUSE
if (event->type == SDL_EVENT_KEY_DOWN) {

View File

@@ -915,6 +915,8 @@ void Title::iterate() {
// Si el juego demo está activo, delega el frame
if (demoGameActive) {
// El demo Game necesita section->name == SECTION_PROG_GAME para funcionar
section->name = SECTION_PROG_GAME;
demoGame->iterate();
if (demoGame->hasFinished()) {
@@ -934,6 +936,9 @@ void Title::iterate() {
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
}
} else {
// Restaura section para que Director no transicione fuera de Title
section->name = SECTION_PROG_TITLE;
}
return;
}
@@ -987,11 +992,13 @@ void Title::runInstructions(mode_e mode) {
// Inicia el juego en modo demo
void Title::runDemoGame() {
// Guardamos el section actual para que Game pueda funcionar
// Temporalmente ponemos section para que el constructor de Game funcione
section->name = SECTION_PROG_GAME;
section->subsection = SUBSECTION_GAME_PLAY_1P;
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, options, section);
demoGameActive = true;
// Restauramos section para que Director no transicione fuera de Title
section->name = SECTION_PROG_TITLE;
}
// Modifica las opciones para los controles de los jugadores