Subversion Repositories Kolibri OS

Rev

Rev 5315 | 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[] = " 0000   ";
  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 not 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_game_over_titles[] = {
  55.     " "L_GAME_OVER,
  56.     " "L_YOUR_SCORE,
  57.     level_passed_score_str,
  58.     " ",
  59.     "0"L_BACK,
  60.     0
  61. };
  62.  
  63.  
  64. char* menu_pause_titles[] = {
  65.     " "L_PAUSE,
  66.     " ",
  67.     "d"L_RESUME,
  68.     "0"L_EXIT_TO_MAIN_MENU,
  69.     0
  70. };
  71.  
  72.  
  73. char **menu_titles[] = {
  74.     /* 0 */ menu_main_titles,
  75.     /* 1 */ menu_settings_titles,
  76.     /* 2 */ menu_about_titles,
  77.     /* 3 */ menu_game_over_titles,
  78.     /* 4 */ menu_pause_titles,
  79.     0
  80. };
  81.  
  82.  
  83. void menu_cursor_down() {
  84.     int new_index = game.menu_item_index+1;
  85.     while ( (menu_titles[game.menu_index][new_index]) ) {
  86.         if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
  87.             game.menu_item_index = new_index;
  88.             game_ding(1);
  89.             return;
  90.         };
  91.         new_index++;
  92.     };
  93. };
  94.  
  95. void menu_cursor_up() {
  96.     int new_index = game.menu_item_index-1;
  97.     while ( new_index+1 ) {
  98.         if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
  99.             game.menu_item_index = new_index;
  100.             game_ding(1);
  101.             return;
  102.         };
  103.         new_index--;
  104.     };
  105. };
  106.  
  107. void menu_open(int i) {
  108.    
  109.     if ( ((game.menu_index == MENU_PAUSE) && (i != MENU_PAUSE)) || (i == MENU_GAME_OVER) ) {
  110.         soundbuf_play( &game.sound_music, SND_MODE_LOOP );
  111.     };
  112.  
  113.     game.menu_index = i;
  114.    
  115.     game.menu_item_index = -1;
  116.     // (menu_cursor_down without sound)
  117.     int new_index = game.menu_item_index+1;
  118.     while ( (menu_titles[game.menu_index][new_index]) ) {
  119.         if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
  120.             game.menu_item_index = new_index;
  121.             return;
  122.         };
  123.         new_index++;
  124.     };
  125.    
  126. };
  127.  
  128. void menu_cursor_click() {
  129.    
  130.     char c = menu_titles[game.menu_index][game.menu_item_index][0];
  131.    
  132.     game_ding(0);
  133.    
  134.     if (c > '9') {
  135.         // action: call function
  136.         menu_actions[c - 'a']();
  137.     }
  138.     else {
  139.         // action: navigate to menu
  140.         menu_open(c - '0');
  141.     };
  142.    
  143. //    DEBUG10f("click: %c \n", c);
  144.    
  145. };
  146.  
  147. void menu_action_start() {
  148.     game.status = STATUS_PLAYING;
  149.    
  150.     game.player_x = GAME_WIDTH/2 - 50;
  151.     game.player_y = GAME_HEIGHT/2 - 10;
  152.    
  153.     game.stage = 0;
  154.     game.stage_timer = 0;
  155.    
  156.     game.health = GAME_HEALTH_MAX;
  157.     game.ammo = GAME_AMMO_MAX;
  158.    
  159.     game.shoot_delay = 0;
  160.     game.shoot_keypressed = 0;
  161.     game.shoot_restore_delay = 0;
  162.    
  163.     game.score = 0;
  164.     game.flags = 0;
  165.    
  166.     game.stage_level = 0;
  167.    
  168.     game.objs_count = 0;
  169.    
  170.     game.bg_color = COLOR_BLACK;
  171.    
  172.     soundbuf_stop( &game.sound_music );
  173.    
  174. };
  175.  
  176. void menu_action_exit() {
  177.     #ifdef RS_KOS
  178.         GameTerm();
  179.     #endif
  180.     rskos_exit();
  181. };
  182.  
  183. void menu_action_change_window_scale() {
  184.     game_change_window_scale(1);
  185. };
  186.  
  187. void menu_action_resume() {
  188.    
  189.     game.status = STATUS_PLAYING;
  190.    
  191. };
  192.