8 http://www.newbreedsoftware.com/supertux/
10 December 20, 2003 - December 30, 2003
15 #include <sys/types.h>
27 #include "leveleditor.h"
30 #include "high_scores.h"
42 strcpy(input_string, "");
45 /* ---- Menu Options - Item Sound On/off ----*/
46 void menu_option_sound()
48 if (audio_device == YES)
54 text_drawf(&red_text, "Sound ON", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
58 text_drawf(&red_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
61 if(menuaction == MN_HIT)
62 { /* Disable/Enable sound */
77 text_drawf(&blue_text, "Sound ON", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
79 text_drawf(&blue_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
83 { /* if audio_device != YES */
84 /* let the user move over the deactivated option */
87 text_drawf(&red_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
91 text_drawf(&red_text, "Sound OFF", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
97 /* ---- Menu Options - Item Music On/off ----*/
98 void menu_option_music()
100 if (audio_device == YES)
106 text_drawf(&red_text, "Music ON", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
110 text_drawf(&red_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
112 if(menuaction == MN_HIT)
113 { /* Disable/Enable music */
115 { /* In the menu no music is played, so we have to check only use_music */
123 if (!playing_music())
125 play_current_music();
130 } /* if menuitem != 2 : print normal blue font */
135 text_drawf(&blue_text, "Music ON", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
139 text_drawf(&blue_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
144 { /* if audio_device != YES */
145 /* let the user move over the deactivated option */
148 text_drawf(&red_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
152 text_drawf(&black_text, "Music OFF", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
159 /* Does the menu item exist? If not, we reset to the most down item */
160 if(menuitem > MENU_MAIN_ITEM_MAX)
162 else if(menuitem < 0)
163 menuitem = MENU_MAIN_ITEM_MAX;
165 /*The menu looks different, when the game is started */
168 text_drawf(&red_text, "Start Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
169 if(menuaction == MN_HIT) /* we are ready to start the game, if this item got hit */
176 text_drawf(&blue_text, "Start Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
180 text_drawf(&red_text, "Options", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
181 if(menuaction == MN_HIT) /* Switch to the 'Options' menu */
183 menumenu = MENU_OPTIONS;
188 text_drawf(&blue_text, "Options", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
192 text_drawf(&red_text, "Level editor", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
193 if(menuaction == MN_HIT) /* Set variables, so that the level editor is executed */
195 level_editor_started = YES;
200 text_drawf(&blue_text, "Level editor", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
204 text_drawf(&red_text, "Quit", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
205 if(menuaction == MN_HIT) /* Quit a running game or the application */
212 text_drawf(&blue_text, "Quit", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
220 /* Does the menu item exist? If not, we reset to the most down item */
221 if(menuitem > MENU_GAME_ITEM_MAX)
223 else if(menuitem < 0)
224 menuitem = MENU_GAME_ITEM_MAX;
226 /*The menu looks different, when the game is started */
229 text_drawf(&red_text, "Return To Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
230 if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
233 st_pause_ticks_stop();
237 text_drawf(&blue_text, "Return To Game", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
241 text_drawf(&red_text, "Save Game", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
242 if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
249 text_drawf(&blue_text, "Save Game", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
253 text_drawf(&red_text, "Load Game", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
254 if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
256 char *x = NULL; /* In C, you can do this... */
263 text_drawf(&blue_text, "Load Game", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
267 text_drawf(&red_text, "Options", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
268 if(menuaction == MN_HIT) /* Switch to the 'Options' menu */
270 menumenu = MENU_OPTIONS;
275 text_drawf(&blue_text, "Options", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
279 text_drawf(&red_text, "Quit Game", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
280 if(menuaction == MN_HIT) /* Quit a running game */
285 text_drawf(&blue_text, "Quit Game", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
291 int menu_options(void)
293 if(menuitem > MENU_OPTIONS_ITEM_MAX )
295 else if(menuitem < 0)
296 menuitem = MENU_OPTIONS_ITEM_MAX;
301 text_drawf(&red_text, "Fullscreen ON", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
303 text_drawf(&red_text, "Fullscreen OFF", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
304 if(menuaction == MN_HIT) /* Disable/Enable fullscreen */
317 text_drawf(&blue_text, "Fullscreen ON", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
319 text_drawf(&blue_text, "Fullscreen OFF", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
322 /* handle menu sound on/off option */
325 /* handle menu music on/off option */
330 text_drawf(&red_text, "Back", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
331 if(menuaction == MN_HIT) /* Go back to main menu. */
334 menumenu = MENU_GAME;
336 menumenu = MENU_MAIN;
341 text_drawf(&blue_text, "Back", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
346 /* Menu LevelEditor */
347 int menu_leveleditor(void)
349 if(menuitem > MENU_LEVELEDITOR_ITEM_MAX )
351 else if(menuitem < 0)
352 menuitem = MENU_LEVELEDITOR_ITEM_MAX;
356 text_drawf(&red_text, "Return To Level Editor", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
357 if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
361 text_drawf(&blue_text, "Return To Level Editor", 0, 192, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
365 text_drawf(&red_text, "New Level", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
366 if(menuaction == MN_HIT) /* Don't show the menu anymore, if this item got hit */
373 text_drawf(&blue_text, "New Level", 0, 224, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
377 text_drawf(&red_text, "Load Level", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
378 if(menuaction == MN_HIT) /* Create a new Level and load it into the level-editor. */
385 text_drawf(&blue_text, "Load Level", 0, 256, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
389 text_drawf(&red_text, "Save Level", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
390 if(menuaction == MN_HIT) /* Save the current level in the level-editor. */
397 text_drawf(&blue_text, "Save Level", 0, 288, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
401 text_drawf(&red_text, "Quit Level Editor", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
402 if(menuaction == MN_HIT) /* Quit the level-editor. (to the main-menu) */
408 text_drawf(&blue_text, "Quit Level Editor", 0, 320, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
413 /* Menu HighScore (ask for player's name) */
416 while(delete_character > 0) /* remove charactes */
418 hs_name[strlen(hs_name)-1] = '\0';
423 strcat(hs_name, input_string);
425 text_drawf(&red_text, "Congratulations", 0, 130, A_HMIDDLE, A_TOP, 2, NO_UPDATE);
426 text_draw(&red_text, "Your score:", 30, 250, 1, NO_UPDATE);
427 sprintf(str, "%d", hs_score);
428 text_draw(&blue_text, str, 350, 250, 1, NO_UPDATE);
430 text_draw(&red_text, "Enter your name:", 30, 280, 1, NO_UPDATE);
431 text_draw(&blue_text, hs_name, 350, 280, 1, NO_UPDATE);
433 strcpy(input_string, "");
435 if(menuaction == MN_HIT) /* name written */
442 /* Draw the menu and execute the (menu)events */
450 if(menuaction == MN_UP)
451 --menuitem; /* Go one menu-item up */
452 else if(menuaction == MN_DOWN)
453 ++menuitem; /* Go one menu-item down */
465 quit = menu_options();
467 case MENU_LEVELEDITOR:
468 quit = menu_leveleditor();
471 quit = menu_highscore();
482 /* Check for menu event */
483 void menu_event(SDL_keysym* keysym)
485 SDLKey key = keysym->sym;
487 keymod = SDL_GetModState();
490 /* If the current unicode character is an ASCII character,
492 if ( (keysym->unicode & 0xFF80) == 0 ) {
493 ch[0] = keysym->unicode & 0x7F;
497 /* An International Character. */
502 case SDLK_UP: /* Menu Up */
506 case SDLK_DOWN: /* Menu Down */
507 menuaction = MN_DOWN;
510 case SDLK_SPACE: /* Menu Hit */
521 if( key >= SDLK_0 && key <= SDLK_9)
522 strcat( input_string, /* (key - SDLK_0) */ ch);
523 else if( key >= SDLK_a && SDLK_z )
525 strcat( input_string, ch);
531 /* FIXME: NO JOYSTICK SUPPORT */
533 else if (event.type == SDL_JOYBUTTONDOWN)
535 Joystick button: Continue: