--- a/sources/auxiliar.cpp +++ b/sources/auxiliar.cpp @@ -20,7 +20,8 @@ char *strupr(char *ptr) { if (ptr!=0) { - char *p=new char[strlen(ptr)+1]; + /* the original walked a new, uninitialized buffer: upper-case the string in place instead */ + char *p=ptr; while(*p!=0) { *p=toupper(*p); --- a/sources/configuration.cpp +++ b/sources/configuration.cpp @@ -29,10 +29,15 @@ return false; } /* if */ - if (2!=fscanf(fp,"%i %i",&fullscreen,&PIXEL_SIZE)) { - fclose(fp); - return false; - } /* if */ + { + /* the original read "%i" straight into the bool */ + int fs; + if (2!=fscanf(fp,"%i %i",&fs,&PIXEL_SIZE)) { + fclose(fp); + return false; + } /* if */ + fullscreen=(fs!=0); + } THRUST_KEY=(SDLKey)a; ANTITHRUST_KEY=(SDLKey)b; --- a/sources/game.cpp +++ b/sources/game.cpp @@ -93,9 +93,15 @@ int replay_source=0; +#ifdef __EMSCRIPTEN__ +SDLKey THRUST_KEY=SDLK_UP,ANTITHRUST_KEY=SDLK_DOWN,LEFT_KEY=SDLK_LEFT,RIGHT_KEY=SDLK_RIGHT; +SDLKey FIRE_KEY=SDLK_SPACE,ATRACTOR_KEY=SDLK_RETURN; +SDLKey PAUSE_KEY=SDLK_p; +#else SDLKey THRUST_KEY=SDLK_q,ANTITHRUST_KEY=SDLK_a,LEFT_KEY=SDLK_o,RIGHT_KEY=SDLK_p; SDLKey FIRE_KEY=SDLK_SPACE,ATRACTOR_KEY=SDLK_RETURN; SDLKey PAUSE_KEY=SDLK_F1; +#endif bool pause2=false; unsigned char old_keyboard[SDLK_LAST]; --- a/sources/main.cpp +++ b/sources/main.cpp @@ -47,7 +47,16 @@ int frames_per_sec_tmp=0; int init_time=0; -char *datadir="/usr/share/games/supertransball2/"; +#ifdef __EMSCRIPTEN__ +/* fredygames.com browser build: the data is preloaded at /data, and the page keeps $HOME/.supertransball2 + (configuration, replays) in the browser's IndexedDB. The window keys (Alt+Enter, Alt+1..4, F12) are off: + the page scales the game itself and there is nothing to quit to. */ +#define ST2_WINDOW_KEYS 0 +char *datadir="/data/"; +#else +#define ST2_WINDOW_KEYS 1 +char *datadir="/usr/share/games/supertransball2/"; +#endif char *confdir; /* Surfaces: */ @@ -147,7 +156,12 @@ if (!cfg) { cfg=fopen("transball.cfg", "w"); - fprintf(cfg,"%s","113 97 111 112 32 13 282"); +#ifdef __EMSCRIPTEN__ + /* arrow keys to fly, Space to fire, Enter for the tractor beam, P to pause */ + fprintf(cfg,"%s","273 274 276 275 32 13 112"); +#else + fprintf(cfg,"%s","113 97 111 112 32 13 282"); +#endif } fclose(cfg); @@ -161,6 +175,10 @@ bool quit = false; if (!load_configuration()) save_configuration(); +#ifdef __EMSCRIPTEN__ + fullscreen=false; + PIXEL_SIZE=1; +#endif time=init_time=GetTickCount(); screen_sfc = initializeSDL((fullscreen ? SDL_FULLSCREEN : 0)); @@ -178,10 +196,10 @@ modifiers=SDL_GetModState(); - if (event.key.keysym.sym==SDLK_F12) quit = true; + if (ST2_WINDOW_KEYS && event.key.keysym.sym==SDLK_F12) quit = true; - if ((modifiers&KMOD_ALT)!=0) { + if (ST2_WINDOW_KEYS && (modifiers&KMOD_ALT)!=0) { if (event.key.keysym.sym==SDLK_RETURN) { /* Toogle FULLSCREEN mode: */ finalizeSDL(); --- a/sources/state_instructions.cpp +++ b/sources/state_instructions.cpp @@ -88,10 +88,18 @@ font_print(16,10," SUPER TRANSBALL 2 V1.5",screen); font_print(16,30," THE CONTROLS OF THE SHIP ARE [REDEFINIBLE]:",screen); +#ifdef __EMSCRIPTEN__ + /* the browser build starts with the arrow keys (see game.cpp) */ + font_print(16,50," UP - PROPULSORS",screen); + font_print(16,60," DOWN - RETROPROPULSORS [NOT ALL THE SHIPS]",screen); + font_print(16,70," LEFT - TURN LEFT",screen); + font_print(16,80," RIGHT - TURN RIGHT",screen); +#else font_print(16,50," Q - PROPULSORS",screen); font_print(16,60," A - RETROPROPULSORS [NOT ALL THE SHIPS]",screen); font_print(16,70," O - TURN LEFT",screen); font_print(16,80," P - TURN RIGHT",screen); +#endif font_print(16,90," SPACE - FIRE",screen); font_print(16,100," ENTER - BALL ATRACTOR",screen);