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