8 http://www.newbreedsoftware.com/supertux/
10 December 20, 2003 - December 30, 2003
15 #include <sys/types.h>
28 #include "leveleditor.h"
31 #include "high_scores.h"
43 strcpy(input_string, "");
46 /* ---- Menu Options - Item Sound On/off ----*/
47 void menu_option_sound()
49 if (audio_device == YES)
55 text_drawf(&red_text, "Sound ON", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
59 text_drawf(&red_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
62 if(menuaction == MN_HIT)
63 { /* Disable/Enable sound */
78 text_drawf(&blue_text, "Sound ON", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
80 text_drawf(&blue_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
84 { /* if audio_device != YES */
85 /* let the user move over the deactivated option */
88 text_drawf(&red_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
92 text_drawf(&red_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
98 /* ---- Menu Options - Item Music On/off ----*/
99 void menu_option_music()
101 if (audio_device == YES)
107 text_drawf(&red_text, "Music ON", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
111 text_drawf(&red_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
113 if(menuaction == MN_HIT)
114 { /* Disable/Enable music */
116 { /* In the menu no music is played, so we have to check only use_music */
124 if (!playing_music())
126 play_current_music();
131 } /* if menuitem != 2 : print normal blue font */
136 text_drawf(&blue_text, "Music ON", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
140 text_drawf(&blue_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
145 { /* if audio_device != YES */
146 /* let the user move over the deactivated option */
149 text_drawf(&red_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
153 text_drawf(&black_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
160 /* Does the menu item exist? If not, we reset to the most down item */
161 if(menuitem > MENU_MAIN_ITEM_MAX)
163 else if(menuitem < 0)
164 menuitem = MENU_MAIN_ITEM_MAX;
166 /*The menu looks different, when the game is started */
169 text_drawf(&red_text, "Start Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
170 if(menuaction == MN_HIT) /* we are ready to start the game, if this item got hit */
177 text_drawf(&blue_text, "Start Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
181 text_drawf(&red_text, "Options", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
182 if(menuaction == MN_HIT) /* Switch to the 'Options' menu */
184 menumenu = MENU_OPTIONS;
189 text_drawf(&blue_text, "Options", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
193 text_drawf(&red_text, "Level editor", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
194 if(menuaction == MN_HIT) /* Set variables, so that the level editor is executed */
196 level_editor_started = YES;
201 text_drawf(&blue_text, "Level editor", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
205 text_drawf(&red_text, "Quit", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
206 if(menuaction == MN_HIT) /* Quit a running game or the application */
213 text_drawf(&blue_text, "Quit", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
221 /* Does the menu item exist? If not, we reset to the most down item */
222 if(menuitem > MENU_GAME_ITEM_MAX)
224 else if(menuitem < 0)
225 menuitem = MENU_GAME_ITEM_MAX;
227 /*The menu looks different, when the game is started */
230 text_drawf(&red_text, "Return To Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
231 if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
234 st_pause_ticks_stop();
238 text_drawf(&blue_text, "Return To Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
242 text_drawf(&red_text, "Save Game", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
243 if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
250 text_drawf(&blue_text, "Save Game", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
254 text_drawf(&red_text, "Load Game", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
255 if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
257 char *x = NULL; /* In C, you can do this... */
264 text_drawf(&blue_text, "Load Game", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
268 text_drawf(&red_text, "Options", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
269 if(menuaction == MN_HIT) /* Switch to the 'Options' menu */
271 menumenu = MENU_OPTIONS;
276 text_drawf(&blue_text, "Options", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
280 text_drawf(&red_text, "Quit Game", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
281 if(menuaction == MN_HIT) /* Quit a running game */
286 text_drawf(&blue_text, "Quit Game", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
292 int menu_options(void)
294 if(menuitem > MENU_OPTIONS_ITEM_MAX )
296 else if(menuitem < 0)
297 menuitem = MENU_OPTIONS_ITEM_MAX;
302 text_drawf(&red_text, "Fullscreen ON", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
304 text_drawf(&red_text, "Fullscreen OFF", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
305 if(menuaction == MN_HIT) /* Disable/Enable fullscreen */
318 text_drawf(&blue_text, "Fullscreen ON", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
320 text_drawf(&blue_text, "Fullscreen OFF", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
323 /* handle menu sound on/off option */
326 /* handle menu music on/off option */
331 text_drawf(&red_text, "Back", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
332 if(menuaction == MN_HIT) /* Go back to main menu. */
335 menumenu = MENU_GAME;
337 menumenu = MENU_MAIN;
342 text_drawf(&blue_text, "Back", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
347 /* Menu LevelEditor */
348 int menu_leveleditor(void)
350 if(menuitem > MENU_LEVELEDITOR_ITEM_MAX )
352 else if(menuitem < 0)
353 menuitem = MENU_LEVELEDITOR_ITEM_MAX;
357 text_drawf(&red_text, "Return To Level Editor", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
358 if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
362 text_drawf(&blue_text, "Return To Level Editor", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
366 text_drawf(&red_text, "New Level", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
367 if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
374 text_drawf(&blue_text, "New Level", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
378 text_drawf(&red_text, "Load Level", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
379 if(menuaction == MN_HIT) /* Create a new Level and load it into the level-editor. */
386 text_drawf(&blue_text, "Load Level", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
390 text_drawf(&red_text, "Save Level", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
391 if(menuaction == MN_HIT) /* Save the current level in the level-editor. */
394 savelevel(¤t_level,"default",level);
395 text_drawf(&gold_text, "SAVED!", 0, 240, A_HMIDDLE, A_TOP, 1, NO_UPDATE);
401 text_drawf(&blue_text, "Save Level", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
405 text_drawf(&red_text, "Quit Level Editor", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
406 if(menuaction == MN_HIT) /* Quit the level-editor. (to the main-menu) */
412 text_drawf(&blue_text, "Quit Level Editor", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
417 /* Menu HighScore (ask for player's name) */
420 while(delete_character > 0) /* remove charactes */
422 hs_name[strlen(hs_name)-1] = '\0';
427 strcat(hs_name, input_string);
429 text_drawf(&red_text, "Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
430 text_draw(&red_text, "Your score:", 30, 250, 1, NO_UPDATE);
431 sprintf(str, "%d", hs_score);
432 text_draw(&blue_text, str, 350, 250, 1, NO_UPDATE);
434 text_draw(&red_text, "Enter your name:", 30, 280, 1, NO_UPDATE);
435 text_draw(&blue_text, hs_name, 350, 280, 1, NO_UPDATE);
437 strcpy(input_string, "");
439 if(menuaction == MN_HIT) /* name written */
446 /* Draw the menu and execute the (menu)events */
454 if(menuaction == MN_UP)
455 --menuitem; /* Go one menu-item up */
456 else if(menuaction == MN_DOWN)
457 ++menuitem; /* Go one menu-item down */
469 quit = menu_options();
471 case MENU_LEVELEDITOR:
472 quit = menu_leveleditor();
475 quit = menu_highscore();
486 /* Check for menu event */
487 void menu_event(SDL_keysym* keysym)
489 SDLKey key = keysym->sym;
491 keymod = SDL_GetModState();
494 /* If the current unicode character is an ASCII character,
496 if ( (keysym->unicode & 0xFF80) == 0 ) {
497 ch[0] = keysym->unicode & 0x7F;
501 /* An International Character. */
506 case SDLK_UP: /* Menu Up */
510 case SDLK_DOWN: /* Menu Down */
511 menuaction = MN_DOWN;
514 case SDLK_SPACE: /* Menu Hit */
525 if( key >= SDLK_0 && key <= SDLK_9)
526 strcat( input_string, /* (key - SDLK_0) */ ch);
527 else if( key >= SDLK_a && SDLK_z )
529 strcat( input_string, ch);
535 /* FIXME: NO JOYSTICK SUPPORT */
537 else if (event.type == SDL_JOYBUTTONDOWN)
539 Joystick button: Continue: