migrat a SDL3 Callback API (SDL_AppInit/Iterate/Event/Quit) (milestone 3)
- main.cpp reescrit amb SDL_MAIN_USE_CALLBACKS - Director convertit a màquina d'estats amb iterate() i handleEvent() - Seccions (Logo, Intro, Title, Game) amb iterate() i handleEvent() - Events SDL enrutats via SDL_AppEvent → Director → secció activa - Eliminat SDL_PollEvent de iterate(), events via handleEvent() - Transicions entre seccions gestionades per handleSectionTransition() - Instructions i Game (demo) delegats frame a frame des de Title Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2950,7 +2950,6 @@ void Game::iterate() {
|
||||
enterPausedGame();
|
||||
}
|
||||
updatePausedGame();
|
||||
checkEvents();
|
||||
renderPausedGame();
|
||||
}
|
||||
|
||||
@@ -2960,7 +2959,6 @@ void Game::iterate() {
|
||||
enterGameOverScreen();
|
||||
}
|
||||
updateGameOverScreen();
|
||||
checkGameOverEvents();
|
||||
renderGameOverScreen();
|
||||
}
|
||||
|
||||
@@ -2988,9 +2986,6 @@ void Game::iterate() {
|
||||
update();
|
||||
#endif
|
||||
|
||||
// Comprueba los eventos que hay en cola
|
||||
checkEvents();
|
||||
|
||||
// Dibuja los objetos
|
||||
render();
|
||||
}
|
||||
@@ -3001,6 +2996,34 @@ bool Game::hasFinished() const {
|
||||
return section->name != SECTION_PROG_GAME;
|
||||
}
|
||||
|
||||
// Procesa un evento individual
|
||||
void Game::handleEvent(SDL_Event *event) {
|
||||
// SDL_EVENT_QUIT ya lo maneja Director
|
||||
|
||||
if (event->type == SDL_EVENT_WINDOW_FOCUS_LOST) {
|
||||
section->subsection = SUBSECTION_GAME_PAUSE;
|
||||
}
|
||||
|
||||
#ifdef PAUSE
|
||||
if (event->type == SDL_EVENT_KEY_DOWN) {
|
||||
if (event->key.scancode == SDL_SCANCODE_P) {
|
||||
pause = !pause;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Eventos específicos de la pantalla de game over
|
||||
if (section->subsection == SUBSECTION_GAME_GAMEOVER) {
|
||||
if (event->type == SDL_EVENT_KEY_DOWN && event->key.repeat == 0) {
|
||||
if (gameCompleted) {
|
||||
gameOverPostFade = 1;
|
||||
fade->activateFade();
|
||||
JA_PlaySound(itemPickUpSound);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bucle para el juego
|
||||
void Game::run() {
|
||||
while (!hasFinished()) {
|
||||
|
||||
Reference in New Issue
Block a user