Subversion Repositories Kolibri OS

Rev

Rev 5302 | Rev 5315 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #include "rsgamemenu.h"
  2.  
  3. #include "rsgame.h"
  4.  
  5. #include "rskos.h"
  6.  
  7. #include "strings.h"
  8.  
  9. PRSFUNC0 menu_actions[] = {
  10.     /* a */ &menu_action_start,    
  11.     /* b */ &menu_action_exit,
  12.     /* c */ &menu_action_change_window_scale,
  13.     /* d */ &menu_action_resume
  14. };
  15.  
  16. char window_scale_str[] = "c< 2X >";
  17. char level_passed_score_str[] = " 000   ";
  18.  
  19. /*
  20.     First char:
  21.     - letter a...z means action (a = 0th, b = 1st, c = 2nd, see menu_actions[] above)
  22.     - number 0...9 means goto menu #0, #1, #2... see menu_titles[] below
  23.     - space ' ' means no action, menu item is unselectable
  24.     - empty string "" is now allowed and can cause segfault
  25.     String from second char is label of menu item
  26.  
  27. */
  28.  
  29.  
  30. char* menu_main_titles[] = {
  31.     "a"L_START,
  32.     "1"L_SETTINGS,
  33.     "2"L_ABOUT,
  34.     "b"L_QUIT,
  35.     0
  36. };
  37.  
  38. char* menu_settings_titles[] = {
  39.     " "L_WINDOW_SCALE,
  40.     window_scale_str,
  41.     " ",
  42.     "0"L_DONE,
  43.     0
  44. };
  45.  
  46. char* menu_about_titles[] = {
  47.     " "L_DEVELOPED_BY,
  48.     " "L_ROMAN_SHUVALOV,
  49.     " ",
  50.     "0"L_BACK,
  51.     0
  52. };
  53.  
  54. char* menu_level_passed_titles[] = {
  55.     " "L_LEVEL_PASSED,
  56.     " "L_YOUR_SCORE,
  57.     level_passed_score_str,
  58.     " ",
  59.     "0"L_BACK,
  60.     0
  61. };
  62.  
  63. char* menu_game_over_titles[] = {
  64.     " "L_GAME_OVER,
  65.     " ",
  66.     "0"L_BACK,
  67.     0
  68. };
  69.  
  70. char* menu_pause_titles[] = {
  71.     " "L_PAUSE,
  72.     " ",
  73.     "d"L_RESUME,
  74.     "0"L_EXIT_TO_MAIN_MENU,
  75.     0
  76. };
  77.  
  78.  
  79. char **menu_titles[] = {
  80.     /* 0 */ menu_main_titles,
  81.     /* 1 */ menu_settings_titles,
  82.     /* 2 */ menu_about_titles,
  83.     /* 3 */ menu_level_passed_titles,
  84.     /* 4 */ menu_game_over_titles,
  85.     /* 5 */ menu_pause_titles,
  86.     0
  87. };
  88.  
  89.  
  90. void menu_cursor_down() {
  91.     int new_index = game.menu_item_index+1;
  92.     while ( (menu_titles[game.menu_index][new_index]) ) {
  93.         if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
  94.             game.menu_item_index = new_index;
  95.             game_ding(1);
  96.             return;
  97.         };
  98.         new_index++;
  99.     };
  100. };
  101.  
  102. void menu_cursor_up() {
  103.     int new_index = game.menu_item_index-1;
  104.     while ( new_index+1 ) {
  105.         if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
  106.             game.menu_item_index = new_index;
  107.             game_ding(1);
  108.             return;
  109.         };
  110.         new_index--;
  111.     };
  112. };
  113.  
  114. void menu_open(int i) {
  115.    
  116.     if ( (game.menu_index == MENU_PAUSE) && (i != MENU_PAUSE) ){
  117.         soundbuf_play( &game.sound_music, SND_MODE_LOOP );
  118.     };
  119.  
  120.     game.menu_index = i;
  121.    
  122.     game.menu_item_index = -1;
  123.     // (menu_cursor_down without sound)
  124.     int new_index = game.menu_item_index+1;
  125.     while ( (menu_titles[game.menu_index][new_index]) ) {
  126.         if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
  127.             game.menu_item_index = new_index;
  128.             return;
  129.         };
  130.         new_index++;
  131.     };
  132.    
  133. };
  134.  
  135. void menu_cursor_click() {
  136.    
  137.     char c = menu_titles[game.menu_index][game.menu_item_index][0];
  138.    
  139.     game_ding(0);
  140.    
  141.     if (c > '9') {
  142.         // action: call function
  143.         menu_actions[c - 'a']();
  144.     }
  145.     else {
  146.         // action: navigate to menu
  147.         menu_open(c - '0');
  148.     };
  149.    
  150. //    DEBUG10f("click: %c \n", c);
  151.    
  152. };
  153.  
  154. void menu_action_start() {
  155.     game.status = STATUS_PLAYING;
  156.    
  157.     game.player_x = GAME_WIDTH/2 - 50;
  158.     game.player_y = GAME_HEIGHT/2 - 10;
  159.    
  160.     game.stage = 0;
  161.     game.stage_timer = 0;
  162.    
  163.     game.health = GAME_HEALTH_MAX;
  164.     game.ammo = GAME_AMMO_MAX;
  165.    
  166.     game.shoot_delay = 0;
  167.     game.shoot_keypressed = 0;
  168.     game.shoot_restore_delay = 0;
  169.    
  170.     game.score = 0;
  171.     game.flags = 0;
  172.    
  173.     game.objs_count = 0;
  174.    
  175.     game.bg_color = COLOR_BLACK;
  176.    
  177.     soundbuf_stop( &game.sound_music );
  178.    
  179. };
  180.  
  181. void menu_action_exit() {
  182.     #ifdef RS_KOS
  183.         GameTerm();
  184.     #endif
  185.     rskos_exit();
  186. };
  187.  
  188. void menu_action_change_window_scale() {
  189.     game_change_window_scale(1);
  190. };
  191.  
  192. void menu_action_resume() {
  193.    
  194.     game.status = STATUS_PLAYING;
  195.    
  196. };
  197.