diff --git a/src/menu.cc b/src/menu.cc index 5a7fc74..180e3c9 100644 --- a/src/menu.cc +++ b/src/menu.cc @@ -30,6 +30,14 @@ #include "utils.h" #include "int.h" +#ifdef __EMSCRIPTEN__ +// fredygames.com: no "options" item (the game only says to run the ceferinosetup program, which the +// browser does not have); the items after it move up one place +#define NUM_ITEMS 5 +#else +#define NUM_ITEMS 6 +#endif + menu :: menu(void) { lim_todos = 0; @@ -42,7 +50,7 @@ menu :: ~menu(void) { int i; - for (i = 0; i < 6; i ++) + for (i = 0; i < NUM_ITEMS; i ++) delete item_menu [i]; for (i = 0; i < 3; i ++) @@ -75,7 +83,7 @@ int menu :: iniciar(class mundo *_pmundo, int _modo_video, SDL_Surface *_screen) return 1; } - for (int i = 0; i < 6; i ++) + for (int i = 0; i < NUM_ITEMS; i ++) item_menu [i] = new class item_menu; for (int i = 0; i < 3; i ++) @@ -84,10 +92,16 @@ int menu :: iniciar(class mundo *_pmundo, int _modo_video, SDL_Surface *_screen) item_menu [0]->iniciar (fuente, 0, _("new game")); item_menu [1]->iniciar (fuente, 1, _("how to play")); +#ifdef __EMSCRIPTEN__ + item_menu [2]->iniciar (fuente, 2, _("credits")); + item_menu [3]->iniciar (fuente, 3, _("high scores")); + item_menu [4]->iniciar (fuente, 4, _("exit")); +#else item_menu [2]->iniciar (fuente, 2, _("options")); item_menu [3]->iniciar (fuente, 3, _("credits")); item_menu [4]->iniciar (fuente, 4, _("high scores")); item_menu [5]->iniciar (fuente, 5, _("exit")); +#endif simple_sprite [0]->iniciar(pmundo->libgrafico.ima_tit_1, -594, 616, \ 90, 8); @@ -119,7 +133,7 @@ void menu :: actualizar(void) if (termino_titulo ()) // terminó la animación del titulo { - for (int i = 0; i < 6; i ++) + for (int i = 0; i < NUM_ITEMS; i ++) item_menu [i]->actualizar (); tecla = SDL_GetKeyState(NULL); @@ -129,7 +143,7 @@ void menu :: actualizar(void) { item_menu [opcion]->no_seleccionar (); - if (opcion == 5) + if (opcion == NUM_ITEMS - 1) opcion = 0; else opcion ++; @@ -147,7 +161,7 @@ void menu :: actualizar(void) item_menu[opcion]->no_seleccionar(); if (opcion == 0) - opcion = 5; + opcion = NUM_ITEMS - 1; else opcion --; @@ -160,7 +174,11 @@ void menu :: actualizar(void) // selecciona una opcion if (shot()) { +#ifdef __EMSCRIPTEN__ + switch (opcion >= 2 ? opcion + 1 : opcion) +#else switch (opcion) +#endif { case 0: pmundo->cambiar_escena(JUEGO); @@ -227,7 +245,7 @@ void menu :: imprimir(void) pmundo->reiniciar_reloj(); } - for (i = 0; i < 6; i++) + for (i = 0; i < NUM_ITEMS; i++) { item_menu [i]->imprimir (screen, rect_actual, \ & lim_actual); diff --git a/src/mundo.cc b/src/mundo.cc index e036000..98f7fb9 100644 --- a/src/mundo.cc +++ b/src/mundo.cc @@ -214,6 +214,13 @@ int mundo :: procesar_eventos(SDL_Event *evento) } break; +#ifdef __EMSCRIPTEN__ + // SDL2 reports the focus as a window event; the game pauses when it loses it + case SDL_WINDOWEVENT: + if (evento->window.event == SDL_WINDOWEVENT_FOCUS_LOST) + actual->pausar(); + break; +#else case SDL_ACTIVEEVENT: if (evento->active.state == SDL_APPINPUTFOCUS) @@ -224,6 +231,7 @@ int mundo :: procesar_eventos(SDL_Event *evento) break; +#endif } }