root / proj / project / src / proj.c @ 355
History | View | Annotate | Download (19.4 KB)
1 | 144 | up20180655 | #include <lcom/lcf.h> |
---|---|---|---|
2 | #include <lcom/proj.h> |
||
3 | #include <lcom/liblm.h> |
||
4 | 351 | up20180642 | |
5 | #include "proj.h" |
||
6 | |||
7 | 185 | up20180655 | #include <math.h> |
8 | 144 | up20180655 | |
9 | 149 | up20180655 | #include "proj_macros.h" |
10 | 179 | up20180642 | #include "proj_func.h" |
11 | 147 | up20180655 | |
12 | 153 | up20180655 | #include "interrupts_func.h" |
13 | 270 | up20180655 | #include "makecode_map.h" |
14 | 149 | up20180655 | |
15 | 192 | up20180642 | #include "crosshair.h" |
16 | #include "shooter.h" |
||
17 | 303 | up20180642 | #include "zombie.h" |
18 | 192 | up20180642 | #include "pistol.h" |
19 | #include "nothing.h" |
||
20 | 237 | up20180642 | #include "bullet.h" |
21 | 216 | up20180642 | #include "map1.h" |
22 | 183 | up20180642 | |
23 | 351 | up20180642 | #include "hltp.h" |
24 | 294 | up20180642 | |
25 | 226 | up20180642 | |
26 | 144 | up20180655 | int main(int argc, char* argv[]) { |
27 | |||
28 | lcf_set_language("EN-US");
|
||
29 | |||
30 | 323 | up20180642 | lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
|
31 | 144 | up20180655 | |
32 | 323 | up20180642 | lcf_log_output("/home/lcom/labs/proj/output.txt");
|
33 | 144 | up20180655 | |
34 | if (lcf_start(argc, argv)) return 1; |
||
35 | |||
36 | lcf_cleanup(); |
||
37 | |||
38 | return 0; |
||
39 | } |
||
40 | 147 | up20180655 | |
41 | 346 | up20180642 | #include "singleplayer.h" |
42 | 311 | up20180655 | static int (multiplayer)(void); |
43 | 346 | up20180642 | #include "chat.h" |
44 | 149 | up20180655 | int(proj_main_loop)(int argc, char *argv[]) { |
45 | 328 | up20180642 | (void)argc; (void)argv; |
46 | 170 | up20180642 | |
47 | int r;
|
||
48 | |||
49 | 313 | up20180642 | if(font_init()){ printf("Failed to initialize fonts\n"); return 1; } |
50 | 192 | up20180642 | |
51 | 261 | up20180642 | /// subscribe interrupts
|
52 | if (subscribe_all()) { return 1; } |
||
53 | 170 | up20180642 | |
54 | 297 | up20180642 | /// initialize graphics
|
55 | if(graph_init(GRAPH_MODE)){
|
||
56 | printf("%s: failed to initalize graphics.\n", __func__);
|
||
57 | if (cleanup()) printf("%s: failed to cleanup.\n", __func__); |
||
58 | return 1; |
||
59 | } |
||
60 | 152 | up20180642 | |
61 | 261 | up20180642 | /// Load stuff
|
62 | { |
||
63 | 297 | up20180642 | graph_clear_screen(); |
64 | 314 | up20180642 | text_t *txt = text_ctor(font_get_default(), "Loading...");
|
65 | 309 | up20180642 | text_set_pos(txt, graph_get_XRes()/2, graph_get_YRes()/2); |
66 | text_set_valign(txt, text_valign_center); |
||
67 | text_set_halign(txt, text_halign_center); |
||
68 | text_set_color(txt, TEXT_COLOR); |
||
69 | 297 | up20180642 | text_draw(txt); |
70 | text_dtor(txt); |
||
71 | graph_draw(); |
||
72 | 183 | up20180642 | |
73 | 261 | up20180642 | bsp_crosshair = get_crosshair(); if(bsp_crosshair == NULL) printf("Failed to get crosshair\n"); |
74 | bsp_shooter = get_shooter (); if(bsp_shooter == NULL) printf("Failed to get shooter\n"); |
||
75 | 303 | up20180642 | bsp_zombie = get_zombie (); if(bsp_zombie == NULL) printf("Failed to get zombie\n"); |
76 | 261 | up20180642 | bsp_pistol = get_pistol (); if(bsp_pistol == NULL) printf("Failed to get pistol\n"); |
77 | bsp_nothing = get_nothing (); if(bsp_nothing == NULL) printf("Failed to get nothing\n"); |
||
78 | bsp_bullet = get_bullet (); if(bsp_bullet == NULL) printf("Failed to get bullet\n"); |
||
79 | map1 = get_map1 (); if(map1 == NULL) printf("Failed to get map1\n"); |
||
80 | 226 | up20180642 | |
81 | 261 | up20180642 | sp_crosshair = sprite_ctor(bsp_crosshair); if(sp_crosshair == NULL) printf("Failed to get crosshair sprite\n"); |
82 | } |
||
83 | 226 | up20180642 | |
84 | 314 | up20180642 | menu_t *main_menu = menu_ctor(font_get_default()); |
85 | 299 | up20180642 | menu_add_item(main_menu, "Single player");
|
86 | menu_add_item(main_menu, "Multiplayer");
|
||
87 | 297 | up20180642 | menu_add_item(main_menu, "Chat");
|
88 | menu_add_item(main_menu, "Exit");
|
||
89 | 234 | up20180655 | |
90 | 297 | up20180642 | //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
91 | uint8_t last_lb = 0;
|
||
92 | struct packet pp;
|
||
93 | keys_t *keys = get_key_presses(); |
||
94 | |||
95 | 261 | up20180642 | /// loop stuff
|
96 | 297 | up20180642 | int click = 0; |
97 | 323 | up20180642 | uint64_t int_vector = 0;
|
98 | 295 | up20180642 | int good = true; |
99 | while (good) {
|
||
100 | 261 | up20180642 | /* Get a request message. */
|
101 | 307 | up20180642 | if((r = get_interrupts_vector(&int_vector))) return r; |
102 | 321 | up20180642 | uint32_t n = 1;
|
103 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
104 | 307 | up20180642 | if (int_vector & n) {
|
105 | interrupt_handler(i); |
||
106 | switch (i) {
|
||
107 | case TIMER0_IRQ:
|
||
108 | 192 | up20180642 | |
109 | 307 | up20180642 | graph_clear_screen(); |
110 | switch(menu_update_state(main_menu, click)){
|
||
111 | case -1: break; |
||
112 | case 0: singleplayer(); break; //campaign(); break; |
||
113 | 311 | up20180655 | case 1: multiplayer() ; break; |
114 | 307 | up20180642 | case 2: chat(); break; |
115 | case 3: good = false; break; |
||
116 | } |
||
117 | menu_draw(main_menu); |
||
118 | 192 | up20180642 | |
119 | 307 | up20180642 | click = 0;
|
120 | 202 | up20180655 | |
121 | 307 | up20180642 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
122 | sprite_draw(sp_crosshair); |
||
123 | graph_draw(); |
||
124 | 231 | up20180655 | |
125 | 307 | up20180642 | break;
|
126 | case KBC_IRQ:
|
||
127 | 321 | up20180642 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false; |
128 | 307 | up20180642 | case MOUSE_IRQ:
|
129 | 323 | up20180642 | if (mouse_get_counter_mouse_ih() >= 3) { |
130 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
131 | 307 | up20180642 | update_mouse(&pp); |
132 | if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
|
||
133 | last_lb = keys->lb_pressed; |
||
134 | 323 | up20180642 | mouse_set_counter_mouse_ih(0);
|
135 | 261 | up20180642 | } |
136 | 307 | up20180642 | break;
|
137 | case COM1_IRQ: nctp_ih(); break; |
||
138 | 305 | up20180642 | } |
139 | 147 | up20180655 | } |
140 | } |
||
141 | 261 | up20180642 | } |
142 | 149 | up20180655 | |
143 | 261 | up20180642 | basic_sprite_dtor (bsp_crosshair); bsp_crosshair = NULL;
|
144 | basic_sprite_dtor (bsp_shooter ); bsp_shooter = NULL;
|
||
145 | 307 | up20180642 | basic_sprite_dtor (bsp_zombie ); bsp_zombie = NULL;
|
146 | 261 | up20180642 | sprite_dtor (sp_crosshair ); sp_crosshair = NULL;
|
147 | basic_sprite_dtor (bsp_pistol ); bsp_pistol = NULL;
|
||
148 | basic_sprite_dtor (bsp_nothing ); bsp_nothing = NULL;
|
||
149 | map_dtor (map1 ); map1 = NULL;
|
||
150 | 319 | up20180642 | font_free(); |
151 | 243 | up20180642 | |
152 | 261 | up20180642 | // Unsubscribe interrupts
|
153 | if (unsubscribe_all()) {
|
||
154 | if (cleanup())
|
||
155 | 305 | up20180642 | printf("%s: failed to cleanup.\n", __func__);
|
156 | 261 | up20180642 | return 1; |
157 | } |
||
158 | 188 | up20180642 | |
159 | 261 | up20180642 | if (cleanup()) {
|
160 | printf("%s: failed to cleanup.\n", __func__);
|
||
161 | return 1; |
||
162 | } |
||
163 | 155 | up20180655 | |
164 | 149 | up20180655 | return 0; |
165 | 147 | up20180655 | } |
166 | 294 | up20180642 | |
167 | 321 | up20180642 | static host_info_t *host_info = NULL; |
168 | static remote_info_t *remote_info = NULL; |
||
169 | static bullet_info_t *bullet_info = NULL; |
||
170 | 308 | up20180655 | |
171 | 311 | up20180655 | static void multiplayer_process(const uint8_t *p, const size_t sz) { |
172 | void *dest = NULL; |
||
173 | hltp_type tp = hltp_interpret(p, sz, &dest); |
||
174 | 342 | up20180655 | if (dest == NULL) return; |
175 | 311 | up20180655 | switch(tp){
|
176 | case hltp_type_host:
|
||
177 | 320 | up20180655 | host_info = (host_info_t*)dest; |
178 | 311 | up20180655 | break;
|
179 | case hltp_type_remote:
|
||
180 | 320 | up20180655 | remote_info = (remote_info_t*)dest; |
181 | 311 | up20180655 | break;
|
182 | 320 | up20180655 | case hltp_type_bullet:
|
183 | bullet_info = (bullet_info_t*)dest; |
||
184 | break;
|
||
185 | 321 | up20180642 | case hltp_type_invalid: break; |
186 | case hltp_type_string : break; |
||
187 | 311 | up20180655 | } |
188 | } |
||
189 | static int (multiplayer_host)(void); |
||
190 | static int (multiplayer_remote)(void); |
||
191 | static int (multiplayer)(void) { |
||
192 | int r;
|
||
193 | 308 | up20180655 | |
194 | 314 | up20180642 | menu_t *main_menu = menu_ctor(font_get_default()); |
195 | 311 | up20180655 | menu_add_item(main_menu, "Create");
|
196 | menu_add_item(main_menu, "Connect");
|
||
197 | menu_add_item(main_menu, "Back");
|
||
198 | 308 | up20180655 | |
199 | 311 | up20180655 | //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
200 | uint8_t last_lb = 0;
|
||
201 | struct packet pp;
|
||
202 | keys_t *keys = get_key_presses(); |
||
203 | 308 | up20180655 | |
204 | 311 | up20180655 | /// loop stuff
|
205 | int click = 0; |
||
206 | 323 | up20180642 | uint64_t int_vector = 0;
|
207 | 311 | up20180655 | int good = true; |
208 | while (good) {
|
||
209 | /* Get a request message. */
|
||
210 | if((r = get_interrupts_vector(&int_vector))) return r; |
||
211 | 321 | up20180642 | uint32_t n = 1;
|
212 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
213 | 311 | up20180655 | if (int_vector & n) {
|
214 | interrupt_handler(i); |
||
215 | switch (i) {
|
||
216 | case TIMER0_IRQ:
|
||
217 | 308 | up20180655 | |
218 | 311 | up20180655 | graph_clear_screen(); |
219 | switch(menu_update_state(main_menu, click)){
|
||
220 | case -1: break; |
||
221 | case 0: multiplayer_host(); break; |
||
222 | case 1: multiplayer_remote(); break; |
||
223 | case 2: good = false; break; |
||
224 | } |
||
225 | menu_draw(main_menu); |
||
226 | |||
227 | click = 0;
|
||
228 | |||
229 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
||
230 | sprite_draw(sp_crosshair); |
||
231 | graph_draw(); |
||
232 | |||
233 | break;
|
||
234 | case KBC_IRQ:
|
||
235 | 321 | up20180642 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false; |
236 | 311 | up20180655 | case MOUSE_IRQ:
|
237 | 323 | up20180642 | if (mouse_get_counter_mouse_ih() >= 3) { |
238 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
239 | 311 | up20180655 | update_mouse(&pp); |
240 | if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
|
||
241 | last_lb = keys->lb_pressed; |
||
242 | 323 | up20180642 | mouse_set_counter_mouse_ih(0);
|
243 | 311 | up20180655 | } |
244 | break;
|
||
245 | case COM1_IRQ: nctp_ih(); break; |
||
246 | } |
||
247 | } |
||
248 | } |
||
249 | } |
||
250 | return 0; |
||
251 | 308 | up20180655 | } |
252 | |||
253 | 311 | up20180655 | static int (multiplayer_host)(void) { |
254 | 320 | up20180655 | int r;
|
255 | 308 | up20180655 | |
256 | 311 | up20180655 | nctp_dump(); |
257 | 320 | up20180655 | nctp_set_processor(multiplayer_process); |
258 | 311 | up20180655 | |
259 | 308 | up20180655 | ent_set_scale(DEFAULT_SCALE); |
260 | 345 | up20180642 | text_timer_t *in_game_timer = text_timer_ctor(font_get_default()); |
261 | 308 | up20180655 | |
262 | list_t *shooter_list = list_ctor(); |
||
263 | |||
264 | 321 | up20180642 | gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
265 | 308 | up20180655 | gunner_set_spawn(shooter1, 75, 75); |
266 | |||
267 | 321 | up20180642 | gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 2); if(shooter2 == NULL) printf("Failed to get shooter2\n"); |
268 | 308 | up20180655 | gunner_set_spawn(shooter2, 975, 75); |
269 | |||
270 | list_insert(shooter_list, list_end(shooter_list), shooter1); |
||
271 | list_insert(shooter_list, list_end(shooter_list), shooter2); |
||
272 | |||
273 | do {
|
||
274 | get_random_spawn(map1, shooter1, shooter_list); |
||
275 | get_random_spawn(map1, shooter2, shooter_list); |
||
276 | 339 | up20180642 | } while (gunner_distance(shooter1, shooter2) < 500); |
277 | 308 | up20180655 | |
278 | 320 | up20180655 | host_info = host_info_ctor(shooter1, shooter2); |
279 | remote_info = remote_info_ctor(); |
||
280 | bullet_info = bullet_info_ctor(); |
||
281 | |||
282 | 308 | up20180655 | list_t *bullet_list = list_ctor(); |
283 | |||
284 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
||
285 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
||
286 | |||
287 | //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
||
288 | uint8_t last_lb = 0;
|
||
289 | struct packet pp;
|
||
290 | keys_t *keys = get_key_presses(); |
||
291 | /// loop stuff
|
||
292 | 323 | up20180642 | uint64_t int_vector = 0;
|
293 | 308 | up20180655 | int good = true; |
294 | 311 | up20180655 | int state = 0; // -1 for remote win, 0 for draw, 1 for host win |
295 | 320 | up20180655 | list_node_t *p1, *p2; // player states
|
296 | int state_1, state_2;
|
||
297 | 311 | up20180655 | while (good) {
|
298 | if ((r = get_interrupts_vector(&int_vector))) return r; |
||
299 | 321 | up20180642 | uint32_t n = 1;
|
300 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
301 | 320 | up20180655 | if (int_vector & n) {
|
302 | interrupt_handler(i); |
||
303 | switch (i) {
|
||
304 | case TIMER0_IRQ:
|
||
305 | 345 | up20180642 | if (timer_get_no_interrupts() % 60 == 0) text_timer_update(in_game_timer); |
306 | 320 | up20180655 | update_movement(map1, shooter1, keys, shooter_list); |
307 | update_movement(map1, shooter2, &(remote_info->remote_keys_pressed), shooter_list); |
||
308 | 308 | up20180655 | |
309 | 320 | up20180655 | update_game_state(map1, shooter_list, bullet_list); |
310 | 311 | up20180655 | |
311 | 320 | up20180655 | p1 = list_find(shooter_list, shooter1); |
312 | p2 = list_find(shooter_list, shooter2); |
||
313 | 311 | up20180655 | |
314 | 320 | up20180655 | if ((state_1 = (p1 == list_end(shooter_list))) || (state_2 = (p2 == list_end(shooter_list)))) {
|
315 | state = state_1 - state_2; |
||
316 | good = false;
|
||
317 | break;
|
||
318 | } |
||
319 | 311 | up20180655 | |
320 | 320 | up20180655 | double angle = get_mouse_angle(shooter1);
|
321 | gunner_set_angle(shooter1, angle - M_PI_2); |
||
322 | 311 | up20180655 | |
323 | 320 | up20180655 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
324 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
||
325 | 311 | up20180655 | |
326 | 320 | up20180655 | gunner_set_angle(shooter2, remote_info->remote_angle); |
327 | 349 | up20180655 | build_host_structure(host_info, shooter1, shooter2); |
328 | 320 | up20180655 | |
329 | 349 | up20180655 | hltp_send_host_info(host_info); |
330 | 320 | up20180655 | |
331 | graph_clear_screen(); |
||
332 | map_draw (map1); |
||
333 | bullet_draw_list(bullet_list); |
||
334 | gunner_draw_list(shooter_list); |
||
335 | |||
336 | text_draw(in_game_timer->text); |
||
337 | |||
338 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
||
339 | sprite_draw(sp_crosshair); |
||
340 | graph_draw(); |
||
341 | |||
342 | break;
|
||
343 | case KBC_IRQ:
|
||
344 | 321 | up20180642 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) { |
345 | 320 | up20180655 | good = false;
|
346 | } |
||
347 | break;
|
||
348 | case MOUSE_IRQ:
|
||
349 | 323 | up20180642 | if (mouse_get_counter_mouse_ih() >= 3) { |
350 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
351 | 320 | up20180655 | update_mouse(&pp); |
352 | if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
|
||
353 | shoot_bullet(shooter1, bullet_list, bsp_bullet); |
||
354 | last_lb = keys->lb_pressed; |
||
355 | 323 | up20180642 | mouse_set_counter_mouse_ih(0);
|
356 | 320 | up20180655 | } |
357 | break;
|
||
358 | |||
359 | case COM1_IRQ:
|
||
360 | nctp_ih(); |
||
361 | if (bullet_info->new_bullet) {
|
||
362 | shoot_bullet(shooter2, bullet_list, bsp_bullet); |
||
363 | bullet_info->new_bullet = false;
|
||
364 | } |
||
365 | break;
|
||
366 | } |
||
367 | 311 | up20180655 | } |
368 | } |
||
369 | 320 | up20180655 | } |
370 | 311 | up20180655 | |
371 | 320 | up20180655 | while(list_size(shooter_list) > 0){ |
372 | gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
||
373 | gunner_dtor(p); |
||
374 | } |
||
375 | if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
||
376 | |||
377 | while(list_size(bullet_list) > 0){ |
||
378 | bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
||
379 | bullet_dtor(p); |
||
380 | } |
||
381 | if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
||
382 | |||
383 | host_info_dtor(host_info); |
||
384 | remote_info_dtor(remote_info); |
||
385 | bullet_info_dtor(bullet_info); |
||
386 | |||
387 | 330 | up20180655 | nctp_set_processor(NULL);
|
388 | |||
389 | 345 | up20180642 | text_timer_dtor(in_game_timer); in_game_timer = NULL;
|
390 | 320 | up20180655 | |
391 | 308 | up20180655 | return 0; |
392 | 311 | up20180655 | } |
393 | 320 | up20180655 | static int (multiplayer_remote)(void) { |
394 | 311 | up20180655 | int r;
|
395 | 308 | up20180655 | |
396 | 311 | up20180655 | nctp_dump(); |
397 | nctp_set_processor(multiplayer_process); |
||
398 | |||
399 | ent_set_scale(DEFAULT_SCALE); |
||
400 | 345 | up20180642 | text_timer_t *in_game_timer = text_timer_ctor(font_get_default()); |
401 | 311 | up20180655 | |
402 | list_t *shooter_list = list_ctor(); |
||
403 | |||
404 | 321 | up20180642 | gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 2); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
405 | 311 | up20180655 | gunner_set_spawn(shooter1, 75, 75); |
406 | |||
407 | 321 | up20180642 | gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter2 == NULL) printf("Failed to get shooter2\n"); |
408 | 311 | up20180655 | gunner_set_spawn(shooter2, 975, 75); |
409 | |||
410 | list_insert(shooter_list, list_end(shooter_list), shooter1); |
||
411 | list_insert(shooter_list, list_end(shooter_list), shooter2); |
||
412 | |||
413 | 320 | up20180655 | host_info = host_info_ctor(shooter2, shooter1); |
414 | remote_info = remote_info_ctor(); |
||
415 | bullet_info = bullet_info_ctor(); |
||
416 | 311 | up20180655 | |
417 | list_t *bullet_list = list_ctor(); |
||
418 | |||
419 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
||
420 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
||
421 | |||
422 | //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
||
423 | uint8_t last_lb = 0;
|
||
424 | struct packet pp;
|
||
425 | keys_t *keys = get_key_presses(); |
||
426 | |||
427 | /// loop stuff
|
||
428 | 323 | up20180642 | uint64_t int_vector = 0;
|
429 | 311 | up20180655 | int good = true; |
430 | while (good) {
|
||
431 | if ((r = get_interrupts_vector(&int_vector))) return r; |
||
432 | 321 | up20180642 | uint32_t n = 1;
|
433 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
434 | 320 | up20180655 | if (int_vector & n) {
|
435 | interrupt_handler(i); |
||
436 | switch (i) {
|
||
437 | case TIMER0_IRQ:
|
||
438 | 345 | up20180642 | if (timer_get_no_interrupts() % 60 == 0) text_timer_update(in_game_timer); |
439 | 311 | up20180655 | |
440 | 326 | up20180655 | double angle = get_mouse_angle(shooter1) - M_PI_2;
|
441 | 311 | up20180655 | |
442 | 320 | up20180655 | build_remote_structure(remote_info, keys, angle); |
443 | 311 | up20180655 | |
444 | 342 | up20180655 | |
445 | 327 | up20180655 | //hltp_send_remote_info(remote_info);
|
446 | 330 | up20180655 | gunner_set_pos(shooter1, (double)host_info->remote_x, (double)host_info->remote_y); |
447 | gunner_set_angle(shooter1, (double)host_info->remote_angle);
|
||
448 | gunner_set_health(shooter1, (double)host_info->remote_health);
|
||
449 | gunner_set_curr_health(shooter1, (double)host_info->remote_current_health);
|
||
450 | 311 | up20180655 | |
451 | 330 | up20180655 | gunner_set_pos(shooter2, (double)host_info->host_x, (double)host_info->host_y); |
452 | gunner_set_angle(shooter2, (double)host_info->host_angle);
|
||
453 | gunner_set_health(shooter2, (double)host_info->host_health);
|
||
454 | gunner_set_curr_health(shooter2, (double)host_info->host_current_health);
|
||
455 | 311 | up20180655 | |
456 | 320 | up20180655 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
457 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
||
458 | 311 | up20180655 | |
459 | 342 | up20180655 | /*
|
460 | 321 | up20180642 | for (size_t j = 0; j < host_info->no_bullets; j++) {
|
461 | if (host_info->bullets_shooter[j]) { // remote
|
||
462 | 330 | up20180655 | bullet_t *bullet = bullet_ctor(shooter1, bsp_bullet, (double)host_info->bullets_x[j], (double)host_info->bullets_y[j], (double)host_info->bullets_vx[j], (double)host_info->bullets_vy[j]);
|
463 | 320 | up20180655 | list_insert(bullet_list, list_end(bullet_list), bullet);
|
464 | } else { // host
|
||
465 | 330 | up20180655 | bullet_t *bullet = bullet_ctor(shooter2, bsp_bullet, (double)host_info->bullets_x[j], (double)host_info->bullets_y[j], (double)host_info->bullets_vx[j], (double)host_info->bullets_vy[j]);
|
466 | 320 | up20180655 | list_insert(bullet_list, list_end(bullet_list), bullet);
|
467 | }
|
||
468 | 342 | up20180655 | }*/
|
469 | 320 | up20180655 | |
470 | graph_clear_screen(); |
||
471 | map_draw (map1); |
||
472 | bullet_draw_list(bullet_list); |
||
473 | gunner_draw_list(shooter_list); |
||
474 | |||
475 | text_draw(in_game_timer->text); |
||
476 | |||
477 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
||
478 | sprite_draw(sp_crosshair); |
||
479 | graph_draw(); |
||
480 | 342 | up20180655 | /*
|
481 | 320 | up20180655 | while(list_size(bullet_list) > 0){
|
482 | bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list));
|
||
483 | bullet_dtor(p);
|
||
484 | }
|
||
485 | 342 | up20180655 | */
|
486 | 320 | up20180655 | |
487 | break;
|
||
488 | case KBC_IRQ:
|
||
489 | 321 | up20180642 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) { |
490 | 320 | up20180655 | good = false;
|
491 | } |
||
492 | break;
|
||
493 | case MOUSE_IRQ:
|
||
494 | 323 | up20180642 | if (mouse_get_counter_mouse_ih() >= 3) { |
495 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
496 | 320 | up20180655 | update_mouse(&pp); |
497 | if (last_lb ^ keys->lb_pressed && keys->lb_pressed) {
|
||
498 | bullet_info->new_bullet = true;
|
||
499 | 327 | up20180655 | //hltp_send_bullet_info(bullet_info);
|
500 | 320 | up20180655 | } |
501 | last_lb = keys->lb_pressed; |
||
502 | 323 | up20180642 | mouse_set_counter_mouse_ih(0);
|
503 | 320 | up20180655 | } |
504 | break;
|
||
505 | |||
506 | 342 | up20180655 | case COM1_IRQ:
|
507 | nctp_ih(); |
||
508 | break;
|
||
509 | 320 | up20180655 | } |
510 | 311 | up20180655 | } |
511 | } |
||
512 | 320 | up20180655 | } |
513 | 311 | up20180655 | |
514 | 320 | up20180655 | while(list_size(shooter_list) > 0){ |
515 | gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
||
516 | gunner_dtor(p); |
||
517 | } |
||
518 | if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
||
519 | |||
520 | while(list_size(bullet_list) > 0){ |
||
521 | bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
||
522 | bullet_dtor(p); |
||
523 | } |
||
524 | if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
||
525 | |||
526 | host_info_dtor(host_info); |
||
527 | remote_info_dtor(remote_info); |
||
528 | bullet_info_dtor(bullet_info); |
||
529 | |||
530 | 330 | up20180655 | nctp_set_processor(NULL);
|
531 | |||
532 | 345 | up20180642 | text_timer_dtor(in_game_timer); in_game_timer = NULL;
|
533 | 320 | up20180655 | |
534 | 311 | up20180655 | return 0; |
535 | } |