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