Revision 251
menu work
proj.c | ||
---|---|---|
7 | 7 |
#include "proj_func.h" |
8 | 8 |
|
9 | 9 |
#include "kbc.h" |
10 |
#include "kbc_macros.h" |
|
11 |
#include "i8254.h" |
|
10 | 12 |
#include "timer.h" |
11 | 13 |
#include "keyboard.h" |
12 | 14 |
#include "mouse.h" |
... | ... | |
173 | 175 |
|
174 | 176 |
text_timer_t *in_game_timer = timer_ctor(consolas); |
175 | 177 |
|
178 |
menu_t *main_menu = menu_ctor(consolas); |
|
179 |
|
|
176 | 180 |
list_t *shooter_list = list_ctor(); |
177 | 181 |
|
178 | 182 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
... | ... | |
201 | 205 |
/// loop stuff |
202 | 206 |
int ipc_status; |
203 | 207 |
message msg; |
204 |
int good = 1;
|
|
208 |
int game_state = MENU, click = 0;
|
|
205 | 209 |
|
206 |
while (good) {
|
|
210 |
while (game_state != EXIT) {
|
|
207 | 211 |
/* Get a request message. */ |
208 | 212 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
209 | 213 |
printf("driver_receive failed with %d", r); |
... | ... | |
215 | 219 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
216 | 220 |
if (msg.m_notify.interrupts & n) { |
217 | 221 |
interrupt_handler(i); |
218 |
if ((scancode[0]) == ESC_BREAK_CODE) good = 0; |
|
219 |
if (i == 0) { |
|
220 |
if (no_interrupts % 60 == 0) timer_update(in_game_timer); |
|
221 |
//if (no_interrupts % refresh_count_value == 0) { |
|
222 |
update_movement(map1, shooter1, keys, shooter_list); |
|
222 |
switch (i) { |
|
223 |
case TIMER0_IRQ: |
|
224 |
switch (game_state) { |
|
225 |
case MENU: |
|
226 |
if (no_interrupts % 2 == 0){ |
|
227 |
graph_clear_screen(); |
|
228 |
game_state = menu_update_state(main_menu, click); |
|
229 |
menu_draw(main_menu); |
|
223 | 230 |
|
224 |
update_game_state(map1, shooter_list, bullet_list);
|
|
231 |
click = 0;
|
|
225 | 232 |
|
226 |
//update_scale(); |
|
227 | 233 |
sprite_set_pos(sp_crosshair, *mouse_x, *mouse_y); |
228 |
angle = get_mouse_angle(shooter1); |
|
229 |
gunner_set_angle(shooter1, angle - M_PI_2); |
|
230 |
graph_clear_screen(); |
|
234 |
sprite_draw(sp_crosshair); |
|
235 |
graph_draw(); |
|
236 |
} |
|
237 |
break; |
|
238 |
case GAME: |
|
239 |
if (no_interrupts % 60 == 0) timer_update(in_game_timer); |
|
240 |
update_movement(map1, shooter1, keys, shooter_list); |
|
231 | 241 |
|
232 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
233 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
242 |
update_game_state(map1, shooter_list, bullet_list); |
|
234 | 243 |
|
235 |
map_draw (map1);
|
|
236 |
gunner_draw_list(shooter_list);
|
|
237 |
bullet_draw_list(bullet_list);
|
|
244 |
//update_scale();
|
|
245 |
angle = get_mouse_angle(shooter1);
|
|
246 |
gunner_set_angle(shooter1, angle - M_PI_2);
|
|
238 | 247 |
|
239 |
text_draw(in_game_timer->text); |
|
240 |
sprite_draw(sp_crosshair); |
|
241 |
graph_draw(); |
|
242 |
//} |
|
248 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
249 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
250 |
|
|
251 |
graph_clear_screen(); |
|
252 |
map_draw (map1); |
|
253 |
gunner_draw_list(shooter_list); |
|
254 |
bullet_draw_list(bullet_list); |
|
255 |
|
|
256 |
text_draw(in_game_timer->text); |
|
257 |
|
|
258 |
sprite_set_pos(sp_crosshair, *mouse_x, *mouse_y); |
|
259 |
sprite_draw(sp_crosshair); |
|
260 |
graph_draw(); |
|
261 |
break; |
|
243 | 262 |
} |
244 |
else if (i == 12) { |
|
245 |
if (counter_mouse_ih >= 3) { |
|
246 |
mouse_parse_packet(packet_mouse_ih, &pp); |
|
247 |
update_mouse(&pp); |
|
248 |
|
|
249 |
if (last_lb ^ keys->lb_pressed && keys->lb_pressed) { |
|
250 |
shoot_bullet(shooter1, bullet_list, bsp_bullet); |
|
263 |
break; |
|
264 |
case KBC_IRQ: |
|
265 |
switch (game_state) { |
|
266 |
case MENU: |
|
267 |
if ((scancode[0]) == ESC_BREAK_CODE) game_state = EXIT; |
|
268 |
break; |
|
269 |
case GAME: |
|
270 |
if ((scancode[0]) == ESC_BREAK_CODE) { |
|
271 |
game_state = MENU; |
|
272 |
// reset game |
|
273 |
while(list_size(bullet_list) > 0){ |
|
274 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
275 |
bullet_dtor(p); |
|
251 | 276 |
} |
252 |
last_lb = keys->lb_pressed; |
|
253 |
counter_mouse_ih = 0; |
|
254 |
|
|
277 |
list_node_t *it = list_begin(shooter_list); |
|
278 |
while (it != list_end(shooter_list)) { |
|
279 |
gunner_t *p = *(gunner_t**)list_node_val(it); |
|
280 |
get_random_spawn(map1, p); |
|
281 |
gunner_set_curr_health(p, gunner_get_health(p)); |
|
282 |
it = list_node_next(it); |
|
283 |
} |
|
284 |
timer_reset(in_game_timer); |
|
255 | 285 |
} |
286 |
break; |
|
256 | 287 |
} |
288 |
break; |
|
289 |
case MOUSE_IRQ: |
|
290 |
if (counter_mouse_ih >= 3) { |
|
291 |
mouse_parse_packet(packet_mouse_ih, &pp); |
|
292 |
update_mouse(&pp); |
|
293 |
switch (game_state) { |
|
294 |
case MENU: |
|
295 |
if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed; |
|
296 |
break; |
|
297 |
case GAME: |
|
298 |
if (last_lb ^ keys->lb_pressed && keys->lb_pressed) |
|
299 |
shoot_bullet(shooter1, bullet_list, bsp_bullet); |
|
300 |
break; |
|
301 |
} |
|
302 |
last_lb = keys->lb_pressed; |
|
303 |
counter_mouse_ih = 0; |
|
304 |
|
|
305 |
} |
|
306 |
break; |
|
257 | 307 |
} |
258 | 308 |
} |
309 |
} |
|
259 | 310 |
|
260 |
break;
|
|
261 |
default:
|
|
262 |
break; /* no other notifications expected: do nothing */
|
|
263 |
}
|
|
311 |
break; |
|
312 |
default: |
|
313 |
break; /* no other notifications expected: do nothing */ |
|
314 |
} |
|
264 | 315 |
} else { /* received standart message, not a notification */ |
265 | 316 |
/* no standart message expected: do nothing */ |
266 | 317 |
} |
Also available in: Unified diff