Subversion Repositories Kolibri OS

Rev

Rev 5291 | Rev 5302 | 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_
  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.  
  71.  
  72. char **menu_titles[] = {
  73.     /* 0 */ menu_main_titles,
  74.     /* 1 */ menu_settings_titles,
  75.     /* 2 */ menu_about_titles,
  76.     /* 3 */ menu_level_passed_titles,
  77.     /* 4 */ menu_game_over_titles,
  78.     0
  79. };
  80.  
  81.  
  82. void menu_cursor_down() {
  83.     int new_index = game.menu_item_index+1;
  84.     while ( (menu_titles[game.menu_index][new_index]) ) {
  85.         if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
  86.             game.menu_item_index = new_index;
  87.             game_ding(1);
  88.             return;
  89.         };
  90.         new_index++;
  91.     };
  92. };
  93.  
  94. void menu_cursor_up() {
  95.     int new_index = game.menu_item_index-1;
  96.     while ( new_index+1 ) {
  97.         if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
  98.             game.menu_item_index = new_index;
  99.             game_ding(1);
  100.             return;
  101.         };
  102.         new_index--;
  103.     };
  104. };
  105.  
  106. void menu_open(int i) {
  107.    
  108.     game.menu_index = i;
  109.    
  110.     game.menu_item_index = -1;
  111.     // (menu_cursor_down without sound)
  112.     int new_index = game.menu_item_index+1;
  113.     while ( (menu_titles[game.menu_index][new_index]) ) {
  114.         if ((menu_titles[game.menu_index][new_index][0] != ' ')) {
  115.             game.menu_item_index = new_index;
  116.             return;
  117.         };
  118.         new_index++;
  119.     };
  120.    
  121. };
  122.  
  123. void menu_cursor_click() {
  124.    
  125.     char c = menu_titles[game.menu_index][game.menu_item_index][0];
  126.    
  127.     game_ding(0);
  128.    
  129.     if (c > '9') {
  130.         // action: call function
  131.         menu_actions[c - 'a']();
  132.     }
  133.     else {
  134.         // action: navigate to menu
  135.         menu_open(c - '0');
  136.     };
  137.    
  138. //    DEBUG10f("click: %c \n", c);
  139.    
  140. };
  141.  
  142. void menu_action_start() {
  143.     game.status = STATUS_PLAYING;
  144.    
  145.     game.player_x = GAME_WIDTH/2 - 50;
  146.     game.player_y = GAME_HEIGHT/2 - 10;
  147.    
  148.     game.stage = 0;
  149.     game.stage_timer = 0;
  150.    
  151.     game.health = GAME_HEALTH_MAX;
  152.     game.ammo = GAME_AMMO_MAX;
  153.    
  154.     game.shoot_delay = 0;
  155.     game.shoot_keypressed = 0;
  156.     game.shoot_restore_delay = 0;
  157.    
  158.     game.score = 0;
  159.     game.flags = 0;
  160.    
  161.     game.objs_count = 0;
  162.    
  163.     game.bg_color = COLOR_BLACK;
  164.    
  165. };
  166.  
  167. void menu_action_exit() {
  168.     #ifdef RS_KOS
  169.         GameTerm();
  170.     #endif
  171.     rskos_exit();
  172. };
  173.  
  174. void menu_action_change_window_scale() {
  175.     game_change_window_scale(1);
  176. };
  177.