Revision 301
changed shooters
proj.c | ||
---|---|---|
51 | 51 |
font_t *consolas = NULL; |
52 | 52 |
basic_sprite_t *bsp_crosshair = NULL; |
53 | 53 |
basic_sprite_t *bsp_shooter = NULL; |
54 |
basic_sprite_t *bsp_zombie = NULL; |
|
54 | 55 |
basic_sprite_t *bsp_pistol = NULL; |
55 | 56 |
basic_sprite_t *bsp_nothing = NULL; |
56 | 57 |
basic_sprite_t *bsp_bullet = NULL; |
... | ... | |
86 | 87 |
|
87 | 88 |
bsp_crosshair = get_crosshair(); if(bsp_crosshair == NULL) printf("Failed to get crosshair\n"); |
88 | 89 |
bsp_shooter = get_shooter (); if(bsp_shooter == NULL) printf("Failed to get shooter\n"); |
90 |
bsp_zombie = bsp_shooter; if(bsp_zombie == NULL) printf("Failed to get zombie\n"); |
|
89 | 91 |
bsp_pistol = get_pistol (); if(bsp_pistol == NULL) printf("Failed to get pistol\n"); |
90 | 92 |
bsp_nothing = get_nothing (); if(bsp_nothing == NULL) printf("Failed to get nothing\n"); |
91 | 93 |
bsp_bullet = get_bullet (); if(bsp_bullet == NULL) printf("Failed to get bullet\n"); |
... | ... | |
172 | 174 |
|
173 | 175 |
basic_sprite_dtor (bsp_crosshair); bsp_crosshair = NULL; |
174 | 176 |
basic_sprite_dtor (bsp_shooter ); bsp_shooter = NULL; |
177 |
/*basic_sprite_dtor (bsp_zombie );*/ bsp_zombie = NULL; |
|
175 | 178 |
sprite_dtor (sp_crosshair ); sp_crosshair = NULL; |
176 | 179 |
basic_sprite_dtor (bsp_pistol ); bsp_pistol = NULL; |
177 | 180 |
basic_sprite_dtor (bsp_nothing ); bsp_nothing = NULL; |
... | ... | |
194 | 197 |
} |
195 | 198 |
|
196 | 199 |
static int (campaign)(void); |
197 |
|
|
200 |
static int (zombies)(void); |
|
198 | 201 |
static int (singleplayer)(void) { |
199 | 202 |
|
200 | 203 |
int r; |
... | ... | |
236 | 239 |
switch(menu_update_state(main_menu, click)){ |
237 | 240 |
case -1: break; |
238 | 241 |
case 0: campaign(); break; |
239 |
case 1: break; |
|
242 |
case 1: zombies(); break;
|
|
240 | 243 |
case 2: good = false; break; |
241 | 244 |
} |
242 | 245 |
menu_draw(main_menu); |
... | ... | |
285 | 288 |
|
286 | 289 |
list_t *shooter_list = list_ctor(); |
287 | 290 |
|
288 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
|
291 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player); if(shooter1 == NULL) printf("Failed to get shooter1\n");
|
|
289 | 292 |
gunner_set_spawn(shooter1, 75, 75); |
290 | 293 |
gunner_set_pos(shooter1, 75, 75); |
291 | 294 |
|
292 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing); |
|
295 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing, gunner_player);
|
|
293 | 296 |
gunner_set_spawn(shooter2, 975, 75); |
294 | 297 |
gunner_set_pos(shooter2, 775, 75); |
295 | 298 |
|
... | ... | |
398 | 401 |
} |
399 | 402 |
if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
400 | 403 |
|
404 |
while(list_size(bullet_list) > 0){ |
|
405 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
406 |
bullet_dtor(p); |
|
407 |
} |
|
408 |
if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
|
409 |
|
|
410 |
timer_dtor(in_game_timer); in_game_timer = NULL; |
|
411 |
|
|
412 |
return SUCCESS; |
|
413 |
} |
|
414 |
|
|
415 |
#define ZOMBIES_NUM 5 |
|
416 |
#define ZOMBIE_HEALTH_FACTOR 1.1 |
|
417 |
|
|
418 |
static int (zombies)(void){ |
|
419 |
|
|
420 |
int r; |
|
421 |
|
|
422 |
ent_set_scale(DEFAULT_SCALE); |
|
423 |
text_timer_t *in_game_timer = timer_ctor(consolas); |
|
424 |
|
|
425 |
list_t *shooter_list = list_ctor(); |
|
426 |
|
|
427 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
|
428 |
gunner_set_spawn(shooter1, 75, 75); |
|
429 |
gunner_set_pos(shooter1, 75, 75); |
|
430 |
|
|
431 |
list_insert(shooter_list, list_end(shooter_list), shooter1); |
|
432 |
|
|
433 |
list_t *bullet_list = list_ctor(); |
|
434 |
|
|
435 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
436 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
437 |
|
|
438 |
//uint32_t refresh_count_value = sys_hz() / REFRESH_RATE; |
|
439 |
uint8_t last_lb = 0; |
|
440 |
struct packet pp; |
|
441 |
keys_t *keys = get_key_presses(); |
|
442 |
|
|
443 |
/// loop stuff |
|
444 |
int ipc_status; |
|
445 |
message msg; |
|
446 |
int good = true; |
|
447 |
|
|
448 |
int health = 50; |
|
449 |
|
|
450 |
while (good) { |
|
451 |
/* Get a request message. */ |
|
452 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
|
453 |
printf("driver_receive failed with %d", r); |
|
454 |
continue; |
|
455 |
} |
|
456 |
if (is_ipc_notify(ipc_status)) { /* received notification */ |
|
457 |
switch (_ENDPOINT_P(msg.m_source)) { |
|
458 |
case HARDWARE: /* hardware interrupt notification */ |
|
459 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
|
460 |
if (msg.m_notify.interrupts & n) { |
|
461 |
interrupt_handler(i); |
|
462 |
switch (i) { |
|
463 |
case TIMER0_IRQ: //printf("L463\n"); |
|
464 |
|
|
465 |
if (no_interrupts % 60 == 0) timer_update(in_game_timer);//printf("L465\n"); |
|
466 |
update_movement(map1, shooter1, keys, shooter_list);//printf("L466\n"); |
|
467 |
|
|
468 |
update_game_state(map1, shooter_list, bullet_list);//printf("L468\n"); |
|
469 |
|
|
470 |
//update_scale(); |
|
471 |
double angle = get_mouse_angle(shooter1);//printf("L471\n"); |
|
472 |
gunner_set_angle(shooter1, angle - M_PI_2); //printf("L472\n"); |
|
473 |
|
|
474 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
|
475 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
|
476 |
|
|
477 |
while(list_size(shooter_list) < ZOMBIES_NUM){ |
|
478 |
gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, gunner_meelee); |
|
479 |
gunner_set_health(zombie, health); |
|
480 |
gunner_set_curr_health(zombie, health); |
|
481 |
health *= ZOMBIE_HEALTH_FACTOR; |
|
482 |
get_random_spawn(map1, zombie); |
|
483 |
list_push_back(shooter_list, zombie); |
|
484 |
} //printf("L484\n"); |
|
485 |
|
|
486 |
if(list_find(shooter_list, shooter1) == list_end(shooter_list)){ |
|
487 |
good = false; |
|
488 |
break; |
|
489 |
} //printf("L489\n"); |
|
490 |
graph_clear_screen(); |
|
491 |
map_draw (map1); |
|
492 |
gunner_draw_list(shooter_list); |
|
493 |
bullet_draw_list(bullet_list); //printf("L502\n"); |
|
494 |
|
|
495 |
text_draw(in_game_timer->text); |
|
496 |
|
|
497 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
|
498 |
sprite_draw(sp_crosshair); |
|
499 |
graph_draw(); //printf("L508\n"); |
|
500 |
|
|
501 |
break; |
|
502 |
case KBC_IRQ: |
|
503 |
if ((scancode[0]) == ESC_BREAK_CODE) { |
|
504 |
good = false; |
|
505 |
// reset game |
|
506 |
while(list_size(bullet_list) > 0){ |
|
507 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
|
508 |
bullet_dtor(p); |
|
509 |
} |
|
510 |
list_node_t *it = list_begin(shooter_list); |
|
511 |
while (it != list_end(shooter_list)) { |
|
512 |
gunner_t *p = *(gunner_t**)list_node_val(it); |
|
513 |
get_random_spawn(map1, p); |
|
514 |
gunner_set_curr_health(p, gunner_get_health(p)); |
|
515 |
it = list_node_next(it); |
|
516 |
} |
|
517 |
timer_reset(in_game_timer); |
|
518 |
} |
|
519 |
break; |
|
520 |
case MOUSE_IRQ: |
|
521 |
if (counter_mouse_ih >= 3) { |
|
522 |
mouse_parse_packet(packet_mouse_ih, &pp); |
|
523 |
update_mouse(&pp); |
|
524 |
if (last_lb ^ keys->lb_pressed && keys->lb_pressed) |
|
525 |
shoot_bullet(shooter1, bullet_list, bsp_bullet); |
|
526 |
last_lb = keys->lb_pressed; |
|
527 |
counter_mouse_ih = 0; |
|
528 |
|
|
529 |
} |
|
530 |
break; |
|
531 |
case COM1_IRQ: nctp_ih(); break; |
|
532 |
} |
|
533 |
} |
|
534 |
} |
|
535 |
break; |
|
536 |
default: |
|
537 |
break; /* no other notifications expected: do nothing */ |
|
538 |
} |
|
539 |
} else { /* received standart message, not a notification */ |
|
540 |
/* no standart message expected: do nothing */ |
|
541 |
} |
|
542 |
} |
|
543 |
|
|
544 |
while(list_size(shooter_list) > 0){ |
|
545 |
gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
|
546 |
gunner_dtor(p); |
|
547 |
} |
|
548 |
if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
|
549 |
|
|
401 | 550 |
while(list_size(bullet_list) > 0){ |
402 | 551 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
403 | 552 |
bullet_dtor(p); |
Also available in: Unified diff