Rev 5291 | Rev 5302 | Go to most recent revision | 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, |
13 | // /* d */ &menu_action_ |
||
5225 | alpine | 14 | }; |
15 | |||
16 | char window_scale_str[] = "c< 2X >"; |
||
5291 | alpine | 17 | char level_passed_score_str[] = " 000 "; |
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 |
||
24 | - empty string "" is now allowed and can cause segfault |
||
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 | |||
5291 | alpine | 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 | |||
61 | }; |
||
62 | |||
63 | char* menu_game_over_titles[] = { |
||
64 | " "L_GAME_OVER, |
||
65 | " ", |
||
66 | "0"L_BACK, |
||
67 | |||
68 | }; |
||
69 | |||
70 | |||
71 | |||
5225 | alpine | 72 | char **menu_titles[] = { |
73 | /* 0 */ menu_main_titles, |
||
74 | /* 1 */ menu_settings_titles, |
||
75 | /* 2 */ menu_about_titles, |
||
5291 | alpine | 76 | /* 3 */ menu_level_passed_titles, |
77 | /* 4 */ menu_game_over_titles, |
||
5225 | alpine | 78 | |
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 | |||
5291 | alpine | 145 | game.player_x = GAME_WIDTH/2 - 50; |
146 | game.player_y = GAME_HEIGHT/2 - 10; |
||
5225 | alpine | 147 | |
5291 | alpine | 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 | |||
5298 | alpine | 163 | game.bg_color = COLOR_BLACK; |
164 | |||
5225 | alpine | 165 | }; |
166 | |||
167 | void menu_action_exit() { |
||
5243 | alpine | 168 | #ifdef RS_KOS |
5225 | alpine | 169 | GameTerm(); |
170 | #endif |
||
171 | rskos_exit(); |
||
172 | }; |
||
173 | |||
174 | void menu_action_change_window_scale() { |
||
175 | game_change_window_scale(1); |
||
176 | };> |