Rev 5315 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5225 | alpine | 1 | #include "rsgamemenu.h" |
2 | |||
3 | #include "rsgame.h" |
||
4 | |||
5 | #include "rskos.h" |
||
6 | |||
5243 | alpine | 7 | #include "strings.h" |
8 | |||
5225 | alpine | 9 | PRSFUNC0 menu_actions[] = { |
10 | /* a */ &menu_action_start, |
||
11 | /* b */ &menu_action_exit, |
||
5291 | alpine | 12 | /* c */ &menu_action_change_window_scale, |
5310 | alpine | 13 | /* d */ &menu_action_resume |
5225 | alpine | 14 | }; |
15 | |||
16 | char window_scale_str[] = "c< 2X >"; |
||
5315 | alpine | 17 | char level_passed_score_str[] = " 0000 "; |
5225 | alpine | 18 | |
5243 | alpine | 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 |
||
5322 | alpine | 24 | - empty string "" is not allowed and can cause segfault |
5243 | alpine | 25 | String from second char is label of menu item |
26 | |||
27 | */ |
||
28 | |||
29 | |||
5225 | alpine | 30 | char* menu_main_titles[] = { |
5243 | alpine | 31 | "a"L_START, |
32 | "1"L_SETTINGS, |
||
33 | "2"L_ABOUT, |
||
34 | "b"L_QUIT, |
||
5225 | alpine | 35 | |
36 | }; |
||
37 | |||
38 | char* menu_settings_titles[] = { |
||
5243 | alpine | 39 | " "L_WINDOW_SCALE, |
5225 | alpine | 40 | window_scale_str, |
41 | " ", |
||
5243 | alpine | 42 | "0"L_DONE, |
5225 | alpine | 43 | |
44 | }; |
||
45 | |||
46 | char* menu_about_titles[] = { |
||
5243 | alpine | 47 | " "L_DEVELOPED_BY, |
48 | " "L_ROMAN_SHUVALOV, |
||
5225 | alpine | 49 | " ", |
5291 | alpine | 50 | "0"L_BACK, |
5225 | alpine | 51 | |
52 | }; |
||
53 | |||
5315 | alpine | 54 | char* menu_game_over_titles[] = { |
55 | " "L_GAME_OVER, |
||
5291 | alpine | 56 | " "L_YOUR_SCORE, |
57 | level_passed_score_str, |
||
58 | " ", |
||
59 | "0"L_BACK, |
||
60 | |||
61 | }; |
||
62 | |||
63 | |||
5310 | alpine | 64 | char* menu_pause_titles[] = { |
65 | " "L_PAUSE, |
||
66 | " ", |
||
67 | "d"L_RESUME, |
||
68 | "0"L_EXIT_TO_MAIN_MENU, |
||
69 | |||
70 | }; |
||
5291 | alpine | 71 | |
72 | |||
5225 | alpine | 73 | char **menu_titles[] = { |
74 | /* 0 */ menu_main_titles, |
||
75 | /* 1 */ menu_settings_titles, |
||
76 | /* 2 */ menu_about_titles, |
||
5315 | alpine | 77 | /* 3 */ menu_game_over_titles, |
78 | /* 4 */ menu_pause_titles, |
||
5225 | alpine | 79 | |
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) { |
||
5310 | alpine | 108 | |
5315 | alpine | 109 | if ( ((game.menu_index == MENU_PAUSE) && (i != MENU_PAUSE)) || (i == MENU_GAME_OVER) ) { |
5310 | alpine | 110 | soundbuf_play( &game.sound_music, SND_MODE_LOOP ); |
111 | }; |
||
5302 | alpine | 112 | |
5225 | alpine | 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 | |||
5291 | alpine | 150 | game.player_x = GAME_WIDTH/2 - 50; |
151 | game.player_y = GAME_HEIGHT/2 - 10; |
||
5225 | alpine | 152 | |
5291 | alpine | 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 | |||
5315 | alpine | 166 | game.stage_level = 0; |
167 | |||
5291 | alpine | 168 | game.objs_count = 0; |
169 | |||
5298 | alpine | 170 | game.bg_color = COLOR_BLACK; |
171 | |||
5302 | alpine | 172 | soundbuf_stop( &game.sound_music ); |
173 | |||
5225 | alpine | 174 | }; |
175 | |||
176 | void menu_action_exit() { |
||
5243 | alpine | 177 | #ifdef RS_KOS |
5225 | alpine | 178 | GameTerm(); |
179 | #endif |
||
180 | rskos_exit(); |
||
181 | }; |
||
182 | |||
183 | void menu_action_change_window_scale() { |
||
184 | game_change_window_scale(1); |
||
185 | }; |
||
5310 | alpine | 186 | |
187 | void menu_action_resume() { |
||
188 | |||
189 | game.status = STATUS_PLAYING; |
||
190 | |||
191 | };> |