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:
@@ -122,6 +122,9 @@ void Title::init() {
|
||||
demo = true;
|
||||
vibrationStep = 0;
|
||||
vibrationInitialized = false;
|
||||
instructionsActive = false;
|
||||
demoGameActive = false;
|
||||
demoThenInstructions = false;
|
||||
|
||||
// Pone valores por defecto a las opciones de control
|
||||
options->input.clear();
|
||||
@@ -319,10 +322,8 @@ void Title::update() {
|
||||
counter = TITLE_COUNTER;
|
||||
menu.active->reset();
|
||||
if (demo) {
|
||||
demoThenInstructions = true;
|
||||
runDemoGame();
|
||||
if (section->name != SECTION_PROG_QUIT) {
|
||||
runInstructions(m_auto);
|
||||
}
|
||||
} else
|
||||
section->name = SECTION_PROG_LOGO;
|
||||
break;
|
||||
@@ -490,13 +491,8 @@ void Title::update() {
|
||||
}
|
||||
} else if (counter == 0) {
|
||||
if (demo) {
|
||||
demoThenInstructions = true;
|
||||
runDemoGame();
|
||||
if (section->name != SECTION_PROG_QUIT) {
|
||||
runInstructions(m_auto);
|
||||
}
|
||||
init();
|
||||
demo = false;
|
||||
counter = TITLE_COUNTER;
|
||||
} else {
|
||||
section->name = SECTION_PROG_LOGO;
|
||||
}
|
||||
@@ -505,8 +501,6 @@ void Title::update() {
|
||||
// Sección Instrucciones
|
||||
if (section->subsection == SUBSECTION_TITLE_INSTRUCTIONS) {
|
||||
runInstructions(m_auto);
|
||||
counter = TITLE_COUNTER;
|
||||
demo = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -894,25 +888,83 @@ void Title::applyOptions() {
|
||||
|
||||
// Bucle para el titulo del juego
|
||||
void Title::run() {
|
||||
while (section->name == SECTION_PROG_TITLE) {
|
||||
while (section->name == SECTION_PROG_TITLE || instructionsActive || demoGameActive) {
|
||||
// Si las instrucciones están activas, delega el frame
|
||||
if (instructionsActive) {
|
||||
instructions->update();
|
||||
instructions->checkEvents();
|
||||
instructions->render();
|
||||
|
||||
if (instructions->hasFinished()) {
|
||||
bool wasQuit = instructions->isQuitRequested();
|
||||
delete instructions;
|
||||
instructions = nullptr;
|
||||
instructionsActive = false;
|
||||
|
||||
if (wasQuit) {
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
} else if (instructionsMode == m_auto) {
|
||||
// Tras instrucciones automáticas (post-demo o subsection), reinicia título
|
||||
section->name = SECTION_PROG_TITLE;
|
||||
init();
|
||||
demo = true;
|
||||
} else {
|
||||
// Tras instrucciones manuales (HOW TO PLAY), vuelve al menú
|
||||
section->name = SECTION_PROG_TITLE;
|
||||
section->subsection = SUBSECTION_TITLE_3;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Si el juego demo está activo, delega el frame
|
||||
if (demoGameActive) {
|
||||
demoGame->iterate();
|
||||
|
||||
if (demoGame->hasFinished()) {
|
||||
bool wasQuit = (section->name == SECTION_PROG_QUIT);
|
||||
delete demoGame;
|
||||
demoGame = nullptr;
|
||||
demoGameActive = false;
|
||||
|
||||
if (wasQuit) {
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
} else if (demoThenInstructions) {
|
||||
// Restaura el section para Title y lanza instrucciones
|
||||
section->name = SECTION_PROG_TITLE;
|
||||
section->subsection = SUBSECTION_TITLE_3;
|
||||
demoThenInstructions = false;
|
||||
runInstructions(m_auto);
|
||||
} else {
|
||||
section->name = SECTION_PROG_TITLE;
|
||||
section->subsection = SUBSECTION_TITLE_1;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ejecución normal del título
|
||||
update();
|
||||
checkEvents();
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
// Ejecuta la parte donde se muestran las instrucciones
|
||||
// Inicia la parte donde se muestran las instrucciones
|
||||
void Title::runInstructions(mode_e mode) {
|
||||
instructions = new Instructions(renderer, screen, asset, input, lang, section);
|
||||
instructions->run(mode);
|
||||
delete instructions;
|
||||
instructions->start(mode);
|
||||
instructionsActive = true;
|
||||
instructionsMode = mode;
|
||||
}
|
||||
|
||||
// Ejecuta el juego en modo demo
|
||||
// Inicia el juego en modo demo
|
||||
void Title::runDemoGame() {
|
||||
// Guardamos el section actual para que Game pueda funcionar
|
||||
section->name = SECTION_PROG_GAME;
|
||||
section->subsection = SUBSECTION_GAME_PLAY_1P;
|
||||
demoGame = new Game(1, 0, renderer, screen, asset, lang, input, true, options, section);
|
||||
demoGame->run();
|
||||
delete demoGame;
|
||||
demoGameActive = true;
|
||||
}
|
||||
|
||||
// Modifica las opciones para los controles de los jugadores
|
||||
|
||||
Reference in New Issue
Block a user