aplanat sub-bucles anidats de pausa, game over, instruccions i demo (milestone 2)

- Game::runPausedGame() convertit a enterPausedGame() + despatx directe en run()
- Game::runGameOverScreen() convertit a enterGameOverScreen() + despatx directe
- Eliminada variable static postFade, convertida a membre gameOverPostFade
- Extret SDL_PollEvent de updateGameOverScreen() a checkGameOverEvents()
- Game::run() refactoritzat amb iterate() + hasFinished() per preparar callbacks
- Title::runInstructions() i runDemoGame() convertits a no-bloquejants
- Instructions ara usa finished/quitRequested en lloc de modificar section directament
- Instructions exposa start(), update(), checkEvents(), render(), hasFinished()

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 19:15:54 +02:00
parent 9365f80e8b
commit 18c4d6032d
7 changed files with 252 additions and 124 deletions

View File

@@ -17,8 +17,6 @@
#include "texture.h" // for Texture
#include "utils.h" // for color_t, section_t
const Uint8 SELF = 0;
// Constructor
Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset, Input *input, Lang *lang, section_t *section) {
// Copia los punteros
@@ -62,12 +60,13 @@ Instructions::Instructions(SDL_Renderer *renderer, Screen *screen, Asset *asset,
}
// Inicializa variables
section->name = SELF;
ticks = 0;
ticksSpeed = 15;
manualQuit = false;
counter = 0;
counterEnd = 600;
finished = false;
quitRequested = false;
}
// Destructor
@@ -99,15 +98,13 @@ void Instructions::update() {
counter++;
if (counter == counterEnd) {
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
finished = true;
}
} else { // Modo manual
++counter %= 60000;
if (manualQuit) {
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_3;
finished = true;
}
}
}
@@ -215,7 +212,8 @@ void Instructions::checkEvents() {
while (SDL_PollEvent(eventHandler) != 0) {
// Evento de salida de la aplicación
if (eventHandler->type == SDL_EVENT_QUIT) {
section->name = SECTION_PROG_QUIT;
quitRequested = true;
finished = true;
break;
}
}
@@ -224,7 +222,8 @@ void Instructions::checkEvents() {
// Comprueba las entradas
void Instructions::checkInput() {
if (input->checkInput(input_exit, REPEAT_FALSE)) {
section->name = SECTION_PROG_QUIT;
quitRequested = true;
finished = true;
}
else if (input->checkInput(input_window_fullscreen, REPEAT_FALSE)) {
@@ -242,8 +241,7 @@ void Instructions::checkInput() {
else if (input->checkInput(input_pause, REPEAT_FALSE) || input->checkInput(input_accept, REPEAT_FALSE) || input->checkInput(input_fire_left, REPEAT_FALSE) || input->checkInput(input_fire_center, REPEAT_FALSE) || input->checkInput(input_fire_right, REPEAT_FALSE)) {
if (mode == m_auto) {
JA_StopMusic();
section->name = SECTION_PROG_TITLE;
section->subsection = SUBSECTION_TITLE_1;
finished = true;
} else {
if (counter > 30) {
manualQuit = true;
@@ -252,13 +250,41 @@ void Instructions::checkInput() {
}
}
// Bucle para la pantalla de instrucciones
// Bucle para la pantalla de instrucciones (compatibilidad)
void Instructions::run(mode_e mode) {
this->mode = mode;
start(mode);
while (section->name == SELF) {
while (!finished) {
update();
checkEvents();
render();
}
// Aplica los cambios de sección según el resultado
if (quitRequested) {
section->name = SECTION_PROG_QUIT;
} else {
section->name = SECTION_PROG_TITLE;
section->subsection = (mode == m_auto) ? SUBSECTION_TITLE_1 : SUBSECTION_TITLE_3;
}
}
// Inicia las instrucciones (sin bucle)
void Instructions::start(mode_e mode) {
this->mode = mode;
finished = false;
quitRequested = false;
manualQuit = false;
counter = 0;
ticks = 0;
}
// Indica si las instrucciones han terminado
bool Instructions::hasFinished() const {
return finished;
}
// Indica si se ha solicitado salir de la aplicación
bool Instructions::isQuitRequested() const {
return quitRequested;
}