root / proj / src / zombies.c @ 351
History | View | Annotate | Download (4.77 KB)
1 | 345 | up20180642 | #include <lcom/lcf.h> |
---|---|---|---|
2 | |||
3 | #include "zombies.h" |
||
4 | |||
5 | #include "proj.h" |
||
6 | |||
7 | 351 | up20180642 | #include "libs.h" |
8 | |||
9 | 345 | up20180642 | #include "proj_macros.h" |
10 | #include "proj_func.h" |
||
11 | #include "ent.h" |
||
12 | #include "interrupts_func.h" |
||
13 | #include <math.h> |
||
14 | |||
15 | #define ZOMBIES_NUM 5 |
||
16 | #define ZOMBIE_HEALTH_FACTOR 1.1 |
||
17 | int (zombies)(void){ |
||
18 | |||
19 | int r;
|
||
20 | |||
21 | ent_set_scale(DEFAULT_SCALE); |
||
22 | text_timer_t *in_game_timer = text_timer_ctor(font_get_default()); |
||
23 | |||
24 | list_t *shooter_list = list_ctor(); |
||
25 | |||
26 | gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
||
27 | gunner_set_spawn(shooter1, 980, 790); |
||
28 | gunner_set_pos(shooter1, 980, 790); |
||
29 | |||
30 | list_insert(shooter_list, list_end(shooter_list), shooter1); |
||
31 | |||
32 | list_t *bullet_list = list_ctor(); |
||
33 | |||
34 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
||
35 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
||
36 | |||
37 | //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
||
38 | uint8_t last_lb = 0;
|
||
39 | struct packet pp;
|
||
40 | keys_t *keys = get_key_presses(); |
||
41 | |||
42 | /// loop stuff
|
||
43 | uint64_t int_vector = 0;
|
||
44 | int good = true; |
||
45 | int dead = false; |
||
46 | |||
47 | int health = 50; |
||
48 | |||
49 | map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1)); |
||
50 | |||
51 | while (good && !dead) {
|
||
52 | /* Get a request message. */
|
||
53 | if((r = get_interrupts_vector(&int_vector))) return r; |
||
54 | uint32_t n = 1;
|
||
55 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
56 | if(!good || dead) break; |
||
57 | if (int_vector & n) {
|
||
58 | interrupt_handler(i); |
||
59 | switch (i) {
|
||
60 | case TIMER0_IRQ:
|
||
61 | if (timer_get_no_interrupts() % 60 == 0) text_timer_update(in_game_timer); |
||
62 | if (timer_get_no_interrupts() % 6 == 0){ |
||
63 | map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1)); |
||
64 | } |
||
65 | |||
66 | update_movement(map1, shooter1, keys, shooter_list); |
||
67 | |||
68 | update_game_state(map1, shooter_list, bullet_list); |
||
69 | |||
70 | if(list_find(shooter_list, shooter1) == list_end(shooter_list)){
|
||
71 | good = false;
|
||
72 | dead = true;
|
||
73 | break;
|
||
74 | } |
||
75 | |||
76 | double angle = get_mouse_angle(shooter1);
|
||
77 | gunner_set_angle(shooter1, angle - M_PI_2); |
||
78 | |||
79 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
||
80 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
||
81 | |||
82 | while(list_size(shooter_list) < ZOMBIES_NUM+1){ |
||
83 | gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, GUNNER_MELEE | GUNNER_FOLLOW, 3);
|
||
84 | gunner_set_health(zombie, health); |
||
85 | gunner_set_curr_health(zombie, health); |
||
86 | health *= ZOMBIE_HEALTH_FACTOR; |
||
87 | get_random_spawn(map1, zombie, shooter_list); |
||
88 | list_push_back(shooter_list, zombie); |
||
89 | } |
||
90 | |||
91 | graph_clear_screen(); |
||
92 | map_draw (map1); |
||
93 | bullet_draw_list(bullet_list); |
||
94 | gunner_draw_list(shooter_list); |
||
95 | |||
96 | text_draw(in_game_timer->text); |
||
97 | |||
98 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
||
99 | sprite_draw(sp_crosshair); |
||
100 | graph_draw(); |
||
101 | |||
102 | break;
|
||
103 | case KBC_IRQ:
|
||
104 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) { |
||
105 | good = false;
|
||
106 | } |
||
107 | break;
|
||
108 | case MOUSE_IRQ:
|
||
109 | if (mouse_get_counter_mouse_ih() >= 3) { |
||
110 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
111 | update_mouse(&pp); |
||
112 | if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
|
||
113 | shoot_bullet(shooter1, bullet_list, bsp_bullet); |
||
114 | last_lb = keys->lb_pressed; |
||
115 | mouse_set_counter_mouse_ih(0);
|
||
116 | |||
117 | } |
||
118 | break;
|
||
119 | case COM1_IRQ: nctp_ih(); break; |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | } |
||
124 | |||
125 | while(list_size(shooter_list) > 0){ |
||
126 | gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
||
127 | gunner_dtor(p); |
||
128 | } |
||
129 | if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
||
130 | |||
131 | while(list_size(bullet_list) > 0){ |
||
132 | bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
||
133 | bullet_dtor(p); |
||
134 | } |
||
135 | if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
||
136 | |||
137 | if(dead){
|
||
138 | printf("YOU DIED\n");
|
||
139 | } |
||
140 | |||
141 | text_timer_dtor(in_game_timer); in_game_timer = NULL;
|
||
142 | |||
143 | return SUCCESS;
|
||
144 | } |