root / proj / src / proj.c @ 327
History | View | Annotate | Download (37.3 KB)
1 | 144 | up20180655 | #include <lcom/lcf.h> |
---|---|---|---|
2 | #include <lcom/proj.h> |
||
3 | #include <lcom/liblm.h> |
||
4 | 185 | up20180655 | #include <math.h> |
5 | 144 | up20180655 | |
6 | 149 | up20180655 | #include "proj_macros.h" |
7 | 179 | up20180642 | #include "proj_func.h" |
8 | 147 | up20180655 | |
9 | 149 | up20180655 | #include "kbc.h" |
10 | #include "timer.h" |
||
11 | #include "keyboard.h" |
||
12 | 150 | up20180655 | #include "mouse.h" |
13 | 189 | up20180655 | #include "graph.h" |
14 | 291 | up20180642 | #include "menu.h" |
15 | 234 | up20180655 | #include "rtc.h" |
16 | 287 | up20180642 | #include "hltp.h" |
17 | 153 | up20180655 | #include "interrupts_func.h" |
18 | 270 | up20180655 | #include "makecode_map.h" |
19 | 149 | up20180655 | |
20 | 179 | up20180642 | #include "graph.h" |
21 | #include "rectangle.h" |
||
22 | 182 | up20180642 | #include "font.h" |
23 | 192 | up20180642 | #include "ent.h" |
24 | 168 | up20180642 | |
25 | 192 | up20180642 | #include "crosshair.h" |
26 | #include "shooter.h" |
||
27 | 303 | up20180642 | #include "zombie.h" |
28 | 192 | up20180642 | #include "pistol.h" |
29 | #include "nothing.h" |
||
30 | 237 | up20180642 | #include "bullet.h" |
31 | 216 | up20180642 | #include "map1.h" |
32 | 183 | up20180642 | |
33 | 294 | up20180642 | #include "errors.h" |
34 | |||
35 | 226 | up20180642 | #include "list.h" |
36 | |||
37 | 144 | up20180655 | int main(int argc, char* argv[]) { |
38 | |||
39 | lcf_set_language("EN-US");
|
||
40 | |||
41 | 323 | up20180642 | lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
|
42 | 144 | up20180655 | |
43 | 323 | up20180642 | lcf_log_output("/home/lcom/labs/proj/output.txt");
|
44 | 144 | up20180655 | |
45 | if (lcf_start(argc, argv)) return 1; |
||
46 | |||
47 | lcf_cleanup(); |
||
48 | |||
49 | return 0; |
||
50 | } |
||
51 | 147 | up20180655 | |
52 | 321 | up20180642 | static basic_sprite_t *bsp_crosshair = NULL; |
53 | static basic_sprite_t *bsp_shooter = NULL; |
||
54 | static basic_sprite_t *bsp_zombie = NULL; |
||
55 | static basic_sprite_t *bsp_pistol = NULL; |
||
56 | static basic_sprite_t *bsp_nothing = NULL; |
||
57 | static basic_sprite_t *bsp_bullet = NULL; |
||
58 | static map_t *map1 = NULL; |
||
59 | static sprite_t *sp_crosshair = NULL; |
||
60 | 294 | up20180642 | |
61 | 300 | up20180642 | static int (singleplayer)(void); |
62 | 311 | up20180655 | static int (multiplayer)(void); |
63 | 300 | up20180642 | static int (chat)(void); |
64 | 149 | up20180655 | int(proj_main_loop)(int argc, char *argv[]) { |
65 | 170 | up20180642 | |
66 | int r;
|
||
67 | |||
68 | 313 | up20180642 | if(font_init()){ printf("Failed to initialize fonts\n"); return 1; } |
69 | 192 | up20180642 | |
70 | 261 | up20180642 | /// subscribe interrupts
|
71 | if (subscribe_all()) { return 1; } |
||
72 | 170 | up20180642 | |
73 | 297 | up20180642 | /// initialize graphics
|
74 | if(graph_init(GRAPH_MODE)){
|
||
75 | printf("%s: failed to initalize graphics.\n", __func__);
|
||
76 | if (cleanup()) printf("%s: failed to cleanup.\n", __func__); |
||
77 | return 1; |
||
78 | } |
||
79 | 152 | up20180642 | |
80 | 261 | up20180642 | /// Load stuff
|
81 | { |
||
82 | 297 | up20180642 | graph_clear_screen(); |
83 | 314 | up20180642 | text_t *txt = text_ctor(font_get_default(), "Loading...");
|
84 | 309 | up20180642 | text_set_pos(txt, graph_get_XRes()/2, graph_get_YRes()/2); |
85 | text_set_valign(txt, text_valign_center); |
||
86 | text_set_halign(txt, text_halign_center); |
||
87 | text_set_color(txt, TEXT_COLOR); |
||
88 | 297 | up20180642 | text_draw(txt); |
89 | text_dtor(txt); |
||
90 | graph_draw(); |
||
91 | 183 | up20180642 | |
92 | 261 | up20180642 | bsp_crosshair = get_crosshair(); if(bsp_crosshair == NULL) printf("Failed to get crosshair\n"); |
93 | bsp_shooter = get_shooter (); if(bsp_shooter == NULL) printf("Failed to get shooter\n"); |
||
94 | 303 | up20180642 | bsp_zombie = get_zombie (); if(bsp_zombie == NULL) printf("Failed to get zombie\n"); |
95 | 261 | up20180642 | bsp_pistol = get_pistol (); if(bsp_pistol == NULL) printf("Failed to get pistol\n"); |
96 | bsp_nothing = get_nothing (); if(bsp_nothing == NULL) printf("Failed to get nothing\n"); |
||
97 | bsp_bullet = get_bullet (); if(bsp_bullet == NULL) printf("Failed to get bullet\n"); |
||
98 | map1 = get_map1 (); if(map1 == NULL) printf("Failed to get map1\n"); |
||
99 | 226 | up20180642 | |
100 | 261 | up20180642 | sp_crosshair = sprite_ctor(bsp_crosshair); if(sp_crosshair == NULL) printf("Failed to get crosshair sprite\n"); |
101 | } |
||
102 | 226 | up20180642 | |
103 | 314 | up20180642 | menu_t *main_menu = menu_ctor(font_get_default()); |
104 | 299 | up20180642 | menu_add_item(main_menu, "Single player");
|
105 | menu_add_item(main_menu, "Multiplayer");
|
||
106 | 297 | up20180642 | menu_add_item(main_menu, "Chat");
|
107 | menu_add_item(main_menu, "Exit");
|
||
108 | 234 | up20180655 | |
109 | 297 | up20180642 | //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
110 | uint8_t last_lb = 0;
|
||
111 | struct packet pp;
|
||
112 | keys_t *keys = get_key_presses(); |
||
113 | |||
114 | 261 | up20180642 | /// loop stuff
|
115 | 297 | up20180642 | int click = 0; |
116 | 323 | up20180642 | uint64_t int_vector = 0;
|
117 | 295 | up20180642 | int good = true; |
118 | while (good) {
|
||
119 | 261 | up20180642 | /* Get a request message. */
|
120 | 307 | up20180642 | if((r = get_interrupts_vector(&int_vector))) return r; |
121 | 321 | up20180642 | uint32_t n = 1;
|
122 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
123 | 307 | up20180642 | if (int_vector & n) {
|
124 | interrupt_handler(i); |
||
125 | switch (i) {
|
||
126 | case TIMER0_IRQ:
|
||
127 | 192 | up20180642 | |
128 | 307 | up20180642 | graph_clear_screen(); |
129 | switch(menu_update_state(main_menu, click)){
|
||
130 | case -1: break; |
||
131 | case 0: singleplayer(); break; //campaign(); break; |
||
132 | 311 | up20180655 | case 1: multiplayer() ; break; |
133 | 307 | up20180642 | case 2: chat(); break; |
134 | case 3: good = false; break; |
||
135 | } |
||
136 | menu_draw(main_menu); |
||
137 | 192 | up20180642 | |
138 | 307 | up20180642 | click = 0;
|
139 | 202 | up20180655 | |
140 | 307 | up20180642 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
141 | sprite_draw(sp_crosshair); |
||
142 | graph_draw(); |
||
143 | 231 | up20180655 | |
144 | 307 | up20180642 | break;
|
145 | case KBC_IRQ:
|
||
146 | 321 | up20180642 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false; |
147 | 307 | up20180642 | case MOUSE_IRQ:
|
148 | 323 | up20180642 | if (mouse_get_counter_mouse_ih() >= 3) { |
149 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
150 | 307 | up20180642 | update_mouse(&pp); |
151 | if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
|
||
152 | last_lb = keys->lb_pressed; |
||
153 | 323 | up20180642 | mouse_set_counter_mouse_ih(0);
|
154 | 261 | up20180642 | } |
155 | 307 | up20180642 | break;
|
156 | case COM1_IRQ: nctp_ih(); break; |
||
157 | 305 | up20180642 | } |
158 | 147 | up20180655 | } |
159 | } |
||
160 | 261 | up20180642 | } |
161 | 149 | up20180655 | |
162 | 261 | up20180642 | basic_sprite_dtor (bsp_crosshair); bsp_crosshair = NULL;
|
163 | basic_sprite_dtor (bsp_shooter ); bsp_shooter = NULL;
|
||
164 | 307 | up20180642 | basic_sprite_dtor (bsp_zombie ); bsp_zombie = NULL;
|
165 | 261 | up20180642 | sprite_dtor (sp_crosshair ); sp_crosshair = NULL;
|
166 | basic_sprite_dtor (bsp_pistol ); bsp_pistol = NULL;
|
||
167 | basic_sprite_dtor (bsp_nothing ); bsp_nothing = NULL;
|
||
168 | map_dtor (map1 ); map1 = NULL;
|
||
169 | 319 | up20180642 | font_free(); |
170 | 243 | up20180642 | |
171 | 261 | up20180642 | // Unsubscribe interrupts
|
172 | if (unsubscribe_all()) {
|
||
173 | if (cleanup())
|
||
174 | 305 | up20180642 | printf("%s: failed to cleanup.\n", __func__);
|
175 | 261 | up20180642 | return 1; |
176 | } |
||
177 | 188 | up20180642 | |
178 | 261 | up20180642 | if (cleanup()) {
|
179 | printf("%s: failed to cleanup.\n", __func__);
|
||
180 | return 1; |
||
181 | } |
||
182 | 155 | up20180655 | |
183 | 149 | up20180655 | return 0; |
184 | 147 | up20180655 | } |
185 | 294 | up20180642 | |
186 | 321 | up20180642 | static host_info_t *host_info = NULL; |
187 | static remote_info_t *remote_info = NULL; |
||
188 | static bullet_info_t *bullet_info = NULL; |
||
189 | 308 | up20180655 | |
190 | 311 | up20180655 | static void multiplayer_process(const uint8_t *p, const size_t sz) { |
191 | void *dest = NULL; |
||
192 | hltp_type tp = hltp_interpret(p, sz, &dest); |
||
193 | switch(tp){
|
||
194 | case hltp_type_host:
|
||
195 | 320 | up20180655 | host_info_dtor(host_info); |
196 | host_info = (host_info_t*)dest; |
||
197 | 311 | up20180655 | break;
|
198 | case hltp_type_remote:
|
||
199 | 320 | up20180655 | remote_info_dtor(remote_info); |
200 | remote_info = (remote_info_t*)dest; |
||
201 | 311 | up20180655 | break;
|
202 | 320 | up20180655 | case hltp_type_bullet:
|
203 | bullet_info_dtor(bullet_info); |
||
204 | bullet_info = (bullet_info_t*)dest; |
||
205 | break;
|
||
206 | 321 | up20180642 | case hltp_type_invalid: break; |
207 | case hltp_type_string : break; |
||
208 | 311 | up20180655 | } |
209 | } |
||
210 | static int (multiplayer_host)(void); |
||
211 | static int (multiplayer_remote)(void); |
||
212 | static int (multiplayer)(void) { |
||
213 | int r;
|
||
214 | 308 | up20180655 | |
215 | 314 | up20180642 | menu_t *main_menu = menu_ctor(font_get_default()); |
216 | 311 | up20180655 | menu_add_item(main_menu, "Create");
|
217 | menu_add_item(main_menu, "Connect");
|
||
218 | menu_add_item(main_menu, "Back");
|
||
219 | 308 | up20180655 | |
220 | 311 | up20180655 | //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
221 | uint8_t last_lb = 0;
|
||
222 | struct packet pp;
|
||
223 | keys_t *keys = get_key_presses(); |
||
224 | 308 | up20180655 | |
225 | 311 | up20180655 | /// loop stuff
|
226 | int click = 0; |
||
227 | 323 | up20180642 | uint64_t int_vector = 0;
|
228 | 311 | up20180655 | int good = true; |
229 | while (good) {
|
||
230 | /* Get a request message. */
|
||
231 | if((r = get_interrupts_vector(&int_vector))) return r; |
||
232 | 321 | up20180642 | uint32_t n = 1;
|
233 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
234 | 311 | up20180655 | if (int_vector & n) {
|
235 | interrupt_handler(i); |
||
236 | switch (i) {
|
||
237 | case TIMER0_IRQ:
|
||
238 | 308 | up20180655 | |
239 | 311 | up20180655 | graph_clear_screen(); |
240 | switch(menu_update_state(main_menu, click)){
|
||
241 | case -1: break; |
||
242 | case 0: multiplayer_host(); break; |
||
243 | case 1: multiplayer_remote(); break; |
||
244 | case 2: good = false; break; |
||
245 | } |
||
246 | menu_draw(main_menu); |
||
247 | |||
248 | click = 0;
|
||
249 | |||
250 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
||
251 | sprite_draw(sp_crosshair); |
||
252 | graph_draw(); |
||
253 | |||
254 | break;
|
||
255 | case KBC_IRQ:
|
||
256 | 321 | up20180642 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false; |
257 | 311 | up20180655 | case MOUSE_IRQ:
|
258 | 323 | up20180642 | if (mouse_get_counter_mouse_ih() >= 3) { |
259 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
260 | 311 | up20180655 | update_mouse(&pp); |
261 | if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
|
||
262 | last_lb = keys->lb_pressed; |
||
263 | 323 | up20180642 | mouse_set_counter_mouse_ih(0);
|
264 | 311 | up20180655 | } |
265 | break;
|
||
266 | case COM1_IRQ: nctp_ih(); break; |
||
267 | } |
||
268 | } |
||
269 | } |
||
270 | } |
||
271 | return 0; |
||
272 | 308 | up20180655 | } |
273 | |||
274 | 311 | up20180655 | static int (multiplayer_host)(void) { |
275 | 320 | up20180655 | int r;
|
276 | 308 | up20180655 | |
277 | 311 | up20180655 | nctp_dump(); |
278 | 320 | up20180655 | nctp_set_processor(multiplayer_process); |
279 | 311 | up20180655 | |
280 | 308 | up20180655 | ent_set_scale(DEFAULT_SCALE); |
281 | 314 | up20180642 | text_timer_t *in_game_timer = timer_ctor(font_get_default()); |
282 | 308 | up20180655 | |
283 | list_t *shooter_list = list_ctor(); |
||
284 | |||
285 | 321 | up20180642 | gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
286 | 308 | up20180655 | gunner_set_spawn(shooter1, 75, 75); |
287 | |||
288 | 321 | up20180642 | gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 2); if(shooter2 == NULL) printf("Failed to get shooter2\n"); |
289 | 308 | up20180655 | gunner_set_spawn(shooter2, 975, 75); |
290 | |||
291 | list_insert(shooter_list, list_end(shooter_list), shooter1); |
||
292 | list_insert(shooter_list, list_end(shooter_list), shooter2); |
||
293 | |||
294 | do {
|
||
295 | get_random_spawn(map1, shooter1, shooter_list); |
||
296 | get_random_spawn(map1, shooter2, shooter_list); |
||
297 | 320 | up20180655 | } while (distance_gunners(shooter1, shooter2) < 500); |
298 | 308 | up20180655 | |
299 | 320 | up20180655 | host_info = host_info_ctor(shooter1, shooter2); |
300 | remote_info = remote_info_ctor(); |
||
301 | bullet_info = bullet_info_ctor(); |
||
302 | |||
303 | 308 | up20180655 | list_t *bullet_list = list_ctor(); |
304 | |||
305 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
||
306 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
||
307 | |||
308 | //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
||
309 | uint8_t last_lb = 0;
|
||
310 | struct packet pp;
|
||
311 | keys_t *keys = get_key_presses(); |
||
312 | /// loop stuff
|
||
313 | 323 | up20180642 | uint64_t int_vector = 0;
|
314 | 308 | up20180655 | int good = true; |
315 | 311 | up20180655 | int state = 0; // -1 for remote win, 0 for draw, 1 for host win |
316 | 320 | up20180655 | list_node_t *p1, *p2; // player states
|
317 | int state_1, state_2;
|
||
318 | 311 | up20180655 | while (good) {
|
319 | if ((r = get_interrupts_vector(&int_vector))) return r; |
||
320 | 321 | up20180642 | uint32_t n = 1;
|
321 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
322 | 320 | up20180655 | if (int_vector & n) {
|
323 | interrupt_handler(i); |
||
324 | switch (i) {
|
||
325 | case TIMER0_IRQ:
|
||
326 | 321 | up20180642 | if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer); |
327 | 308 | up20180655 | |
328 | 320 | up20180655 | update_movement(map1, shooter1, keys, shooter_list); |
329 | update_movement(map1, shooter2, &(remote_info->remote_keys_pressed), shooter_list); |
||
330 | 308 | up20180655 | |
331 | 320 | up20180655 | update_game_state(map1, shooter_list, bullet_list); |
332 | 311 | up20180655 | |
333 | 320 | up20180655 | p1 = list_find(shooter_list, shooter1); |
334 | p2 = list_find(shooter_list, shooter2); |
||
335 | 311 | up20180655 | |
336 | 320 | up20180655 | if ((state_1 = (p1 == list_end(shooter_list))) || (state_2 = (p2 == list_end(shooter_list)))) {
|
337 | state = state_1 - state_2; |
||
338 | good = false;
|
||
339 | break;
|
||
340 | } |
||
341 | 311 | up20180655 | |
342 | 320 | up20180655 | double angle = get_mouse_angle(shooter1);
|
343 | gunner_set_angle(shooter1, angle - M_PI_2); |
||
344 | 311 | up20180655 | |
345 | 320 | up20180655 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
346 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
||
347 | 311 | up20180655 | |
348 | 320 | up20180655 | gunner_set_angle(shooter2, remote_info->remote_angle); |
349 | |||
350 | build_host_structure(host_info, shooter1, shooter2, bullet_list); |
||
351 | |||
352 | |||
353 | 327 | up20180655 | |
354 | hltp_send_host_info(host_info); |
||
355 | |||
356 | 320 | up20180655 | graph_clear_screen(); |
357 | map_draw (map1); |
||
358 | bullet_draw_list(bullet_list); |
||
359 | gunner_draw_list(shooter_list); |
||
360 | |||
361 | text_draw(in_game_timer->text); |
||
362 | |||
363 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
||
364 | sprite_draw(sp_crosshair); |
||
365 | graph_draw(); |
||
366 | |||
367 | break;
|
||
368 | case KBC_IRQ:
|
||
369 | 321 | up20180642 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) { |
370 | 320 | up20180655 | good = false;
|
371 | } |
||
372 | break;
|
||
373 | case MOUSE_IRQ:
|
||
374 | 323 | up20180642 | if (mouse_get_counter_mouse_ih() >= 3) { |
375 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
376 | 320 | up20180655 | update_mouse(&pp); |
377 | if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
|
||
378 | shoot_bullet(shooter1, bullet_list, bsp_bullet); |
||
379 | last_lb = keys->lb_pressed; |
||
380 | 323 | up20180642 | mouse_set_counter_mouse_ih(0);
|
381 | 320 | up20180655 | } |
382 | break;
|
||
383 | |||
384 | case COM1_IRQ:
|
||
385 | nctp_ih(); |
||
386 | if (bullet_info->new_bullet) {
|
||
387 | shoot_bullet(shooter2, bullet_list, bsp_bullet); |
||
388 | bullet_info->new_bullet = false;
|
||
389 | } |
||
390 | break;
|
||
391 | } |
||
392 | 311 | up20180655 | } |
393 | } |
||
394 | 320 | up20180655 | } |
395 | 311 | up20180655 | |
396 | 320 | up20180655 | while(list_size(shooter_list) > 0){ |
397 | gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
||
398 | gunner_dtor(p); |
||
399 | } |
||
400 | if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
||
401 | |||
402 | while(list_size(bullet_list) > 0){ |
||
403 | bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
||
404 | bullet_dtor(p); |
||
405 | } |
||
406 | if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
||
407 | |||
408 | host_info_dtor(host_info); |
||
409 | remote_info_dtor(remote_info); |
||
410 | bullet_info_dtor(bullet_info); |
||
411 | |||
412 | timer_dtor(in_game_timer); in_game_timer = NULL;
|
||
413 | |||
414 | 308 | up20180655 | return 0; |
415 | 311 | up20180655 | } |
416 | 320 | up20180655 | static int (multiplayer_remote)(void) { |
417 | 311 | up20180655 | int r;
|
418 | 308 | up20180655 | |
419 | 311 | up20180655 | nctp_dump(); |
420 | nctp_set_processor(multiplayer_process); |
||
421 | |||
422 | ent_set_scale(DEFAULT_SCALE); |
||
423 | 314 | up20180642 | text_timer_t *in_game_timer = timer_ctor(font_get_default()); |
424 | 311 | up20180655 | |
425 | list_t *shooter_list = list_ctor(); |
||
426 | |||
427 | 321 | up20180642 | gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 2); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
428 | 311 | up20180655 | gunner_set_spawn(shooter1, 75, 75); |
429 | |||
430 | 321 | up20180642 | gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter2 == NULL) printf("Failed to get shooter2\n"); |
431 | 311 | up20180655 | gunner_set_spawn(shooter2, 975, 75); |
432 | |||
433 | list_insert(shooter_list, list_end(shooter_list), shooter1); |
||
434 | list_insert(shooter_list, list_end(shooter_list), shooter2); |
||
435 | |||
436 | 320 | up20180655 | host_info = host_info_ctor(shooter2, shooter1); |
437 | remote_info = remote_info_ctor(); |
||
438 | bullet_info = bullet_info_ctor(); |
||
439 | 311 | up20180655 | |
440 | list_t *bullet_list = list_ctor(); |
||
441 | |||
442 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
||
443 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
||
444 | |||
445 | //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
||
446 | uint8_t last_lb = 0;
|
||
447 | struct packet pp;
|
||
448 | keys_t *keys = get_key_presses(); |
||
449 | |||
450 | /// loop stuff
|
||
451 | 323 | up20180642 | uint64_t int_vector = 0;
|
452 | 311 | up20180655 | int good = true; |
453 | while (good) {
|
||
454 | if ((r = get_interrupts_vector(&int_vector))) return r; |
||
455 | 321 | up20180642 | uint32_t n = 1;
|
456 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
457 | 320 | up20180655 | if (int_vector & n) {
|
458 | interrupt_handler(i); |
||
459 | switch (i) {
|
||
460 | case TIMER0_IRQ:
|
||
461 | 321 | up20180642 | if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer); |
462 | 311 | up20180655 | |
463 | 326 | up20180655 | double angle = get_mouse_angle(shooter1) - M_PI_2;
|
464 | 311 | up20180655 | |
465 | 320 | up20180655 | build_remote_structure(remote_info, keys, angle); |
466 | 311 | up20180655 | |
467 | 327 | up20180655 | //hltp_send_remote_info(remote_info);
|
468 | 311 | up20180655 | |
469 | 320 | up20180655 | gunner_set_pos(shooter1, host_info->remote_x, host_info->remote_y); |
470 | gunner_set_angle(shooter1, host_info->remote_angle); |
||
471 | gunner_set_health(shooter1, host_info->remote_health); |
||
472 | gunner_set_curr_health(shooter1, host_info->remote_current_health); |
||
473 | 311 | up20180655 | |
474 | 320 | up20180655 | gunner_set_pos(shooter2, host_info->host_x, host_info->host_y); |
475 | gunner_set_angle(shooter2, host_info->host_angle); |
||
476 | gunner_set_health(shooter2, host_info->host_health); |
||
477 | gunner_set_curr_health(shooter2, host_info->host_current_health); |
||
478 | 311 | up20180655 | |
479 | 320 | up20180655 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
480 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
||
481 | 311 | up20180655 | |
482 | 321 | up20180642 | for (size_t j = 0; j < host_info->no_bullets; j++) { |
483 | if (host_info->bullets_shooter[j]) { // remote |
||
484 | bullet_t *bullet = bullet_ctor(shooter1, bsp_bullet, host_info->bullets_x[j], host_info->bullets_y[j], host_info->bullets_vx[j], host_info->bullets_vy[j]); |
||
485 | 320 | up20180655 | list_insert(bullet_list, list_end(bullet_list), bullet); |
486 | } else { // host |
||
487 | 321 | up20180642 | bullet_t *bullet = bullet_ctor(shooter2, bsp_bullet, host_info->bullets_x[j], host_info->bullets_y[j], host_info->bullets_vx[j], host_info->bullets_vy[j]); |
488 | 320 | up20180655 | list_insert(bullet_list, list_end(bullet_list), bullet); |
489 | } |
||
490 | } |
||
491 | |||
492 | graph_clear_screen(); |
||
493 | map_draw (map1); |
||
494 | bullet_draw_list(bullet_list); |
||
495 | gunner_draw_list(shooter_list); |
||
496 | |||
497 | text_draw(in_game_timer->text); |
||
498 | |||
499 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
||
500 | sprite_draw(sp_crosshair); |
||
501 | graph_draw(); |
||
502 | |||
503 | while(list_size(bullet_list) > 0){ |
||
504 | bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
||
505 | bullet_dtor(p); |
||
506 | } |
||
507 | |||
508 | break;
|
||
509 | case KBC_IRQ:
|
||
510 | 321 | up20180642 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) { |
511 | 320 | up20180655 | good = false;
|
512 | } |
||
513 | break;
|
||
514 | case MOUSE_IRQ:
|
||
515 | 323 | up20180642 | if (mouse_get_counter_mouse_ih() >= 3) { |
516 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
517 | 320 | up20180655 | update_mouse(&pp); |
518 | if (last_lb ^ keys->lb_pressed && keys->lb_pressed) {
|
||
519 | bullet_info->new_bullet = true;
|
||
520 | 327 | up20180655 | //hltp_send_bullet_info(bullet_info);
|
521 | 320 | up20180655 | } |
522 | last_lb = keys->lb_pressed; |
||
523 | 323 | up20180642 | mouse_set_counter_mouse_ih(0);
|
524 | 320 | up20180655 | } |
525 | break;
|
||
526 | |||
527 | case COM1_IRQ: nctp_ih(); break; |
||
528 | } |
||
529 | 311 | up20180655 | } |
530 | } |
||
531 | 320 | up20180655 | } |
532 | 311 | up20180655 | |
533 | 320 | up20180655 | while(list_size(shooter_list) > 0){ |
534 | gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
||
535 | gunner_dtor(p); |
||
536 | } |
||
537 | if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
||
538 | |||
539 | while(list_size(bullet_list) > 0){ |
||
540 | bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
||
541 | bullet_dtor(p); |
||
542 | } |
||
543 | if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
||
544 | |||
545 | host_info_dtor(host_info); |
||
546 | remote_info_dtor(remote_info); |
||
547 | bullet_info_dtor(bullet_info); |
||
548 | |||
549 | timer_dtor(in_game_timer); in_game_timer = NULL;
|
||
550 | |||
551 | 311 | up20180655 | return 0; |
552 | } |
||
553 | |||
554 | 300 | up20180642 | static int (campaign)(void); |
555 | 301 | up20180642 | static int (zombies)(void); |
556 | 300 | up20180642 | static int (singleplayer)(void) { |
557 | |||
558 | 295 | up20180642 | int r;
|
559 | |||
560 | 314 | up20180642 | menu_t *main_menu = menu_ctor(font_get_default()); |
561 | 300 | up20180642 | menu_add_item(main_menu, "Campaign");
|
562 | menu_add_item(main_menu, "Zombies");
|
||
563 | menu_add_item(main_menu, "Back");
|
||
564 | |||
565 | //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
||
566 | uint8_t last_lb = 0;
|
||
567 | struct packet pp;
|
||
568 | keys_t *keys = get_key_presses(); |
||
569 | |||
570 | /// loop stuff
|
||
571 | int click = 0; |
||
572 | 323 | up20180642 | uint64_t int_vector = 0;
|
573 | 300 | up20180642 | int good = true; |
574 | while (good) {
|
||
575 | /* Get a request message. */
|
||
576 | 304 | up20180642 | if((r = get_interrupts_vector(&int_vector))) return r; |
577 | 321 | up20180642 | uint32_t n = 1;
|
578 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
579 | 304 | up20180642 | if (int_vector & n) {
|
580 | interrupt_handler(i); |
||
581 | switch (i) {
|
||
582 | 305 | up20180642 | case TIMER0_IRQ:
|
583 | 300 | up20180642 | |
584 | 304 | up20180642 | graph_clear_screen(); |
585 | switch(menu_update_state(main_menu, click)){
|
||
586 | case -1: break; |
||
587 | case 0: campaign(); break; |
||
588 | case 1: zombies(); break; |
||
589 | case 2: good = false; break; |
||
590 | } |
||
591 | menu_draw(main_menu); |
||
592 | 300 | up20180642 | |
593 | 304 | up20180642 | click = 0;
|
594 | 300 | up20180642 | |
595 | 304 | up20180642 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
596 | sprite_draw(sp_crosshair); |
||
597 | graph_draw(); |
||
598 | 300 | up20180642 | |
599 | 304 | up20180642 | break;
|
600 | 305 | up20180642 | case KBC_IRQ:
|
601 | 321 | up20180642 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false; |
602 | 305 | up20180642 | case MOUSE_IRQ:
|
603 | 323 | up20180642 | if (mouse_get_counter_mouse_ih() >= 3) { |
604 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
605 | 304 | up20180642 | update_mouse(&pp); |
606 | if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
|
||
607 | last_lb = keys->lb_pressed; |
||
608 | 323 | up20180642 | mouse_set_counter_mouse_ih(0);
|
609 | 300 | up20180642 | } |
610 | break;
|
||
611 | 305 | up20180642 | case COM1_IRQ: nctp_ih(); break; |
612 | 304 | up20180642 | } |
613 | 300 | up20180642 | } |
614 | } |
||
615 | } |
||
616 | |||
617 | return 0; |
||
618 | } |
||
619 | |||
620 | static int (campaign)(void){ |
||
621 | |||
622 | int r;
|
||
623 | |||
624 | 295 | up20180642 | ent_set_scale(DEFAULT_SCALE); |
625 | 314 | up20180642 | text_timer_t *in_game_timer = timer_ctor(font_get_default()); |
626 | 295 | up20180642 | |
627 | list_t *shooter_list = list_ctor(); |
||
628 | |||
629 | 321 | up20180642 | gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
630 | 295 | up20180642 | gunner_set_spawn(shooter1, 75, 75); |
631 | gunner_set_pos(shooter1, 75, 75); |
||
632 | |||
633 | 321 | up20180642 | gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing, GUNNER_PLAYER, 2);
|
634 | 295 | up20180642 | gunner_set_spawn(shooter2, 975, 75); |
635 | gunner_set_pos(shooter2, 775, 75); |
||
636 | |||
637 | list_insert(shooter_list, list_end(shooter_list), shooter1); |
||
638 | list_insert(shooter_list, list_end(shooter_list), shooter2); |
||
639 | |||
640 | list_t *bullet_list = list_ctor(); |
||
641 | |||
642 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
||
643 | 305 | up20180642 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
644 | 295 | up20180642 | |
645 | 305 | up20180642 | //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
646 | uint8_t last_lb = 0;
|
||
647 | struct packet pp;
|
||
648 | keys_t *keys = get_key_presses(); |
||
649 | 295 | up20180642 | |
650 | /// loop stuff
|
||
651 | 323 | up20180642 | uint64_t int_vector = 0;
|
652 | 296 | up20180642 | int good = true; |
653 | while (good) {
|
||
654 | 304 | up20180642 | /* Get a request message. */
|
655 | if((r = get_interrupts_vector(&int_vector))) return r; |
||
656 | 321 | up20180642 | uint32_t n = 1;
|
657 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
658 | 309 | up20180642 | if(!good) break; |
659 | 305 | up20180642 | if (int_vector & n) {
|
660 | interrupt_handler(i); |
||
661 | switch (i) {
|
||
662 | case TIMER0_IRQ:
|
||
663 | 295 | up20180642 | |
664 | 321 | up20180642 | if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer); |
665 | 305 | up20180642 | update_movement(map1, shooter1, keys, shooter_list); |
666 | 295 | up20180642 | |
667 | 305 | up20180642 | update_game_state(map1, shooter_list, bullet_list); |
668 | 295 | up20180642 | |
669 | 305 | up20180642 | //update_scale();
|
670 | double angle = get_mouse_angle(shooter1);
|
||
671 | gunner_set_angle(shooter1, angle - M_PI_2); |
||
672 | 295 | up20180642 | |
673 | 305 | up20180642 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
674 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
||
675 | 295 | up20180642 | |
676 | 305 | up20180642 | graph_clear_screen(); |
677 | map_draw (map1); |
||
678 | bullet_draw_list(bullet_list); |
||
679 | gunner_draw_list(shooter_list); |
||
680 | 295 | up20180642 | |
681 | 305 | up20180642 | text_draw(in_game_timer->text); |
682 | 295 | up20180642 | |
683 | 305 | up20180642 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
684 | sprite_draw(sp_crosshair); |
||
685 | graph_draw(); |
||
686 | 295 | up20180642 | |
687 | 305 | up20180642 | break;
|
688 | case KBC_IRQ:
|
||
689 | 321 | up20180642 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) { |
690 | 305 | up20180642 | good = false;
|
691 | } |
||
692 | break;
|
||
693 | case MOUSE_IRQ:
|
||
694 | 323 | up20180642 | if (mouse_get_counter_mouse_ih() >= 3) { |
695 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
696 | 305 | up20180642 | update_mouse(&pp); |
697 | if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
|
||
698 | shoot_bullet(shooter1, bullet_list, bsp_bullet); |
||
699 | last_lb = keys->lb_pressed; |
||
700 | 323 | up20180642 | mouse_set_counter_mouse_ih(0);
|
701 | 304 | up20180642 | |
702 | 305 | up20180642 | } |
703 | break;
|
||
704 | case COM1_IRQ: nctp_ih(); break; |
||
705 | } |
||
706 | } |
||
707 | 304 | up20180642 | } |
708 | 295 | up20180642 | } |
709 | |||
710 | while(list_size(shooter_list) > 0){ |
||
711 | gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
||
712 | gunner_dtor(p); |
||
713 | } |
||
714 | 296 | up20180642 | if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
715 | 295 | up20180642 | |
716 | 301 | up20180642 | while(list_size(bullet_list) > 0){ |
717 | bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
||
718 | bullet_dtor(p); |
||
719 | } |
||
720 | if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
||
721 | |||
722 | timer_dtor(in_game_timer); in_game_timer = NULL;
|
||
723 | |||
724 | return SUCCESS;
|
||
725 | } |
||
726 | |||
727 | #define ZOMBIES_NUM 5 |
||
728 | #define ZOMBIE_HEALTH_FACTOR 1.1 |
||
729 | static int (zombies)(void){ |
||
730 | |||
731 | int r;
|
||
732 | |||
733 | ent_set_scale(DEFAULT_SCALE); |
||
734 | 314 | up20180642 | text_timer_t *in_game_timer = timer_ctor(font_get_default()); |
735 | 301 | up20180642 | |
736 | list_t *shooter_list = list_ctor(); |
||
737 | |||
738 | 321 | up20180642 | gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, GUNNER_PLAYER, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
739 | 305 | up20180642 | gunner_set_spawn(shooter1, 980, 790); |
740 | gunner_set_pos(shooter1, 980, 790); |
||
741 | 301 | up20180642 | |
742 | list_insert(shooter_list, list_end(shooter_list), shooter1); |
||
743 | |||
744 | list_t *bullet_list = list_ctor(); |
||
745 | |||
746 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
||
747 | 305 | up20180642 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
748 | 301 | up20180642 | |
749 | 305 | up20180642 | //uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
750 | uint8_t last_lb = 0;
|
||
751 | struct packet pp;
|
||
752 | keys_t *keys = get_key_presses(); |
||
753 | 301 | up20180642 | |
754 | /// loop stuff
|
||
755 | 323 | up20180642 | uint64_t int_vector = 0;
|
756 | 301 | up20180642 | int good = true; |
757 | 302 | up20180642 | int dead = false; |
758 | 301 | up20180642 | |
759 | int health = 50; |
||
760 | |||
761 | 309 | up20180642 | map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1)); |
762 | |||
763 | 302 | up20180642 | while (good && !dead) {
|
764 | 304 | up20180642 | /* Get a request message. */
|
765 | if((r = get_interrupts_vector(&int_vector))) return r; |
||
766 | 321 | up20180642 | uint32_t n = 1;
|
767 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
768 | 309 | up20180642 | if(!good || dead) break; |
769 | 304 | up20180642 | if (int_vector & n) {
|
770 | 305 | up20180642 | interrupt_handler(i); |
771 | switch (i) {
|
||
772 | case TIMER0_IRQ:
|
||
773 | 321 | up20180642 | if (timer_get_no_interrupts() % 60 == 0) timer_update(in_game_timer); |
774 | if (timer_get_no_interrupts() % 6 == 0){ |
||
775 | 309 | up20180642 | map_make_dijkstra(map1, gunner_get_x(shooter1), gunner_get_y(shooter1)); |
776 | } |
||
777 | 301 | up20180642 | |
778 | 305 | up20180642 | update_movement(map1, shooter1, keys, shooter_list); |
779 | 301 | up20180642 | |
780 | 305 | up20180642 | update_game_state(map1, shooter_list, bullet_list); |
781 | 302 | up20180642 | |
782 | 305 | up20180642 | if(list_find(shooter_list, shooter1) == list_end(shooter_list)){
|
783 | good = false;
|
||
784 | dead = true;
|
||
785 | break;
|
||
786 | } |
||
787 | 301 | up20180642 | |
788 | 305 | up20180642 | double angle = get_mouse_angle(shooter1);
|
789 | gunner_set_angle(shooter1, angle - M_PI_2); |
||
790 | 301 | up20180642 | |
791 | 305 | up20180642 | ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
792 | gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
||
793 | 301 | up20180642 | |
794 | 309 | up20180642 | while(list_size(shooter_list) < ZOMBIES_NUM+1){ |
795 | 321 | up20180642 | gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, GUNNER_MELEE | GUNNER_FOLLOW, 3);
|
796 | 305 | up20180642 | gunner_set_health(zombie, health); |
797 | gunner_set_curr_health(zombie, health); |
||
798 | health *= ZOMBIE_HEALTH_FACTOR; |
||
799 | 307 | up20180642 | get_random_spawn(map1, zombie, shooter_list); |
800 | 305 | up20180642 | list_push_back(shooter_list, zombie); |
801 | } |
||
802 | 301 | up20180642 | |
803 | 305 | up20180642 | graph_clear_screen(); |
804 | map_draw (map1); |
||
805 | bullet_draw_list(bullet_list); |
||
806 | gunner_draw_list(shooter_list); |
||
807 | 301 | up20180642 | |
808 | 305 | up20180642 | text_draw(in_game_timer->text); |
809 | 301 | up20180642 | |
810 | 305 | up20180642 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
811 | sprite_draw(sp_crosshair); |
||
812 | graph_draw(); |
||
813 | 304 | up20180642 | |
814 | 305 | up20180642 | break;
|
815 | case KBC_IRQ:
|
||
816 | 321 | up20180642 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) { |
817 | 305 | up20180642 | good = false;
|
818 | } |
||
819 | break;
|
||
820 | case MOUSE_IRQ:
|
||
821 | 323 | up20180642 | if (mouse_get_counter_mouse_ih() >= 3) { |
822 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
823 | 305 | up20180642 | update_mouse(&pp); |
824 | if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
|
||
825 | shoot_bullet(shooter1, bullet_list, bsp_bullet); |
||
826 | last_lb = keys->lb_pressed; |
||
827 | 323 | up20180642 | mouse_set_counter_mouse_ih(0);
|
828 | 305 | up20180642 | |
829 | } |
||
830 | break;
|
||
831 | case COM1_IRQ: nctp_ih(); break; |
||
832 | } |
||
833 | } |
||
834 | } |
||
835 | 301 | up20180642 | } |
836 | |||
837 | while(list_size(shooter_list) > 0){ |
||
838 | gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
||
839 | gunner_dtor(p); |
||
840 | } |
||
841 | if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
||
842 | |||
843 | 295 | up20180642 | while(list_size(bullet_list) > 0){ |
844 | bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
||
845 | bullet_dtor(p); |
||
846 | } |
||
847 | if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
||
848 | |||
849 | 302 | up20180642 | if(dead){
|
850 | printf("YOU DIED\n");
|
||
851 | } |
||
852 | |||
853 | 295 | up20180642 | timer_dtor(in_game_timer); in_game_timer = NULL;
|
854 | |||
855 | 294 | up20180642 | return SUCCESS;
|
856 | } |
||
857 | 296 | up20180642 | |
858 | 298 | up20180642 | #define CHAT_MAX_SIZE 75 |
859 | #define CHAT_MAX_NUM 19 |
||
860 | 321 | up20180642 | static text_t *t_text[CHAT_MAX_NUM] = {NULL}; |
861 | static rectangle_t *r_text = NULL; |
||
862 | 297 | up20180642 | static void chat_process(const uint8_t *p, const size_t sz){ |
863 | char buffer2[CHAT_MAX_NUM+3]; |
||
864 | void *dest = NULL; |
||
865 | hltp_type tp = hltp_interpret(p, sz, &dest); |
||
866 | switch(tp){
|
||
867 | case hltp_type_string:
|
||
868 | 305 | up20180642 | strcpy(buffer2, dest); |
869 | strncat(buffer2, " <", 2); |
||
870 | for(size_t i = CHAT_MAX_NUM-1; i; --i) |
||
871 | 314 | up20180642 | text_set_string(t_text[i], text_get_string(t_text[i-1]));
|
872 | text_set_string(t_text[0], buffer2);
|
||
873 | 305 | up20180642 | for(size_t i = 0; i < CHAT_MAX_NUM; ++i){ |
874 | if(text_get_string(t_text[i])[0] == '>'){ |
||
875 | text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
|
||
876 | text_set_halign(t_text[i], text_halign_left); |
||
877 | }else{
|
||
878 | text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
|
||
879 | text_set_halign(t_text[i], text_halign_right); |
||
880 | 297 | up20180642 | } |
881 | 305 | up20180642 | } |
882 | break;
|
||
883 | 321 | up20180642 | case hltp_type_invalid: break; |
884 | case hltp_type_bullet : break; |
||
885 | case hltp_type_host : break; |
||
886 | case hltp_type_remote : break; |
||
887 | 297 | up20180642 | } |
888 | } |
||
889 | 300 | up20180642 | static int (chat)(void){ |
890 | 297 | up20180642 | int r;
|
891 | |||
892 | 298 | up20180642 | nctp_dump(); |
893 | 297 | up20180642 | nctp_set_processor(chat_process); |
894 | |||
895 | struct packet pp;
|
||
896 | |||
897 | 298 | up20180642 | char buffer[CHAT_MAX_SIZE] = ""; |
898 | 297 | up20180642 | rectangle_t *r_buffer = NULL; {
|
899 | 298 | up20180642 | r_buffer = rectangle_ctor(0,0,900,70); |
900 | 297 | up20180642 | rectangle_set_pos(r_buffer, graph_get_XRes()/2 -rectangle_get_w(r_buffer)/2, |
901 | 321 | up20180642 | (int16_t)(graph_get_YRes()*0.87-rectangle_get_h(r_buffer)/2)); |
902 | 297 | up20180642 | rectangle_set_fill_color (r_buffer, GRAPH_BLACK); |
903 | rectangle_set_outline_width(r_buffer, 2);
|
||
904 | rectangle_set_outline_color(r_buffer, GRAPH_WHITE); |
||
905 | rectangle_set_fill_trans(r_buffer, GRAPH_TRANSPARENT); |
||
906 | } |
||
907 | text_t *t_buffer = NULL; {
|
||
908 | 314 | up20180642 | t_buffer = text_ctor(font_get_default(), "");
|
909 | 297 | up20180642 | text_set_pos(t_buffer, rectangle_get_x(r_buffer)+50,
|
910 | 305 | up20180642 | rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)/2);
|
911 | 297 | up20180642 | text_set_halign(t_buffer, text_halign_left); |
912 | text_set_valign(t_buffer, text_valign_center); |
||
913 | text_set_color (t_buffer, TEXT_COLOR); |
||
914 | } |
||
915 | 298 | up20180642 | text_t *t_size = NULL; {
|
916 | 314 | up20180642 | t_size = text_ctor(font_get_default(), "");
|
917 | 298 | up20180642 | text_set_pos(t_size, rectangle_get_x(r_buffer)+rectangle_get_w(r_buffer)-5,
|
918 | 305 | up20180642 | rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)-5);
|
919 | 298 | up20180642 | text_set_halign(t_size, text_halign_right); |
920 | text_set_valign(t_size, text_valign_bottom); |
||
921 | text_set_color (t_size, TEXT_COLOR); |
||
922 | text_set_size (t_size, 18);
|
||
923 | char buffer2[20]; |
||
924 | sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
|
||
925 | 314 | up20180642 | text_set_string(t_size, buffer2); |
926 | 298 | up20180642 | } |
927 | 297 | up20180642 | |
928 | /** r_text */ {
|
||
929 | 305 | up20180642 | r_text = rectangle_ctor(0,0,900,550); |
930 | rectangle_set_pos(r_text, graph_get_XRes()/2 -rectangle_get_w(r_buffer)/2, |
||
931 | 321 | up20180642 | (int16_t)(graph_get_YRes()*0.09)); |
932 | 305 | up20180642 | rectangle_set_fill_color (r_text, GRAPH_BLACK); |
933 | rectangle_set_outline_width(r_text, 2);
|
||
934 | rectangle_set_outline_color(r_text, GRAPH_WHITE); |
||
935 | rectangle_set_fill_trans(r_text, GRAPH_TRANSPARENT); |
||
936 | 311 | up20180655 | } |
937 | /** t_text */ {
|
||
938 | 321 | up20180642 | for(uint16_t i = 0; i < CHAT_MAX_NUM; ++i){ |
939 | 314 | up20180642 | t_text[i] = text_ctor(font_get_default(), " ");
|
940 | 311 | up20180655 | text_set_pos(t_text[i], rectangle_get_x(r_text)+50,
|
941 | rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i); |
||
942 | text_set_halign(t_text[i], text_halign_left); |
||
943 | text_set_valign(t_text[i], text_valign_bottom); |
||
944 | text_set_color (t_text[i], TEXT_COLOR); |
||
945 | } |
||
946 | 305 | up20180642 | } |
947 | 297 | up20180642 | |
948 | 305 | up20180642 | /// loop stuff
|
949 | 323 | up20180642 | uint64_t int_vector = 0;
|
950 | 305 | up20180642 | int good = true; |
951 | while (good) {
|
||
952 | /* Get a request message. */
|
||
953 | if((r = get_interrupts_vector(&int_vector))) return r; |
||
954 | 321 | up20180642 | uint32_t n = 1;
|
955 | for (uint8_t i = 0; i < 32; i++, n <<= 1) { |
||
956 | 305 | up20180642 | if (int_vector & n) {
|
957 | interrupt_handler(i); |
||
958 | switch (i) {
|
||
959 | 304 | up20180642 | case TIMER0_IRQ:
|
960 | 305 | up20180642 | graph_clear_screen(); |
961 | sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
||
962 | 297 | up20180642 | |
963 | 305 | up20180642 | rectangle_draw(r_buffer); |
964 | text_draw(t_buffer); |
||
965 | text_draw(t_size); |
||
966 | 297 | up20180642 | |
967 | 305 | up20180642 | rectangle_draw(r_text); |
968 | 321 | up20180642 | for(size_t j = 0; j < CHAT_MAX_NUM; ++j) text_draw(t_text[j]); |
969 | 297 | up20180642 | |
970 | 305 | up20180642 | sprite_draw(sp_crosshair); |
971 | graph_draw(); |
||
972 | break;
|
||
973 | 304 | up20180642 | case KBC_IRQ:
|
974 | 321 | up20180642 | if (keyboard_get_scancode()[0] == ESC_BREAK_CODE) good = false; |
975 | else if (keyboard_get_scancode()[0] == ENTER_MAKE_CODE) { |
||
976 | 305 | up20180642 | hltp_send_string(buffer); |
977 | char buffer2[CHAT_MAX_SIZE+3] = "> "; |
||
978 | strncat(buffer2, buffer, strlen(buffer)); |
||
979 | 321 | up20180642 | for(size_t j = CHAT_MAX_NUM-1; j; --j) text_set_string(t_text[i], text_get_string(t_text[i-1])); |
980 | 314 | up20180642 | text_set_string(t_text[0], buffer2);
|
981 | 321 | up20180642 | for(size_t j = 0; j < CHAT_MAX_NUM; ++j){ |
982 | if(text_get_string(t_text[j])[0] == '>'){ |
||
983 | text_set_pos(t_text[j], rectangle_get_x(r_text)+50, text_get_y(t_text[j]));
|
||
984 | text_set_halign(t_text[j], text_halign_left); |
||
985 | 305 | up20180642 | }else{
|
986 | 321 | up20180642 | text_set_pos(t_text[j], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[j]));
|
987 | text_set_halign(t_text[j], text_halign_right); |
||
988 | 297 | up20180642 | } |
989 | } |
||
990 | 305 | up20180642 | buffer[0] = '\0'; |
991 | 321 | up20180642 | } else if(keyboard_get_scancode()[0] == BACKSPACE_MAKE_CODE){ |
992 | 305 | up20180642 | buffer[strlen(buffer)-1] = '\0'; |
993 | } else {
|
||
994 | 321 | up20180642 | char c = map_makecode(keyboard_get_scancode()[0]); |
995 | 305 | up20180642 | if (c == ERROR_CODE) break; |
996 | if(strlen(buffer) < CHAT_MAX_SIZE) strncat(buffer, &c, 1); |
||
997 | else printf("Char limit exceeded\n"); |
||
998 | } |
||
999 | 314 | up20180642 | text_set_string(t_buffer, buffer); |
1000 | 305 | up20180642 | char buffer2[20]; |
1001 | sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
|
||
1002 | 314 | up20180642 | text_set_string(t_size, buffer2); |
1003 | 304 | up20180642 | case MOUSE_IRQ:
|
1004 | 323 | up20180642 | if (mouse_get_counter_mouse_ih() >= 3) { |
1005 | mouse_parse_packet(mouse_get_packet_mouse_ih(), &pp); |
||
1006 | 305 | up20180642 | update_mouse(&pp); |
1007 | 323 | up20180642 | mouse_set_counter_mouse_ih(0);
|
1008 | 305 | up20180642 | } |
1009 | break;
|
||
1010 | 304 | up20180642 | case COM1_IRQ: nctp_ih(); break; |
1011 | 297 | up20180642 | } |
1012 | } |
||
1013 | } |
||
1014 | 305 | up20180642 | } |
1015 | 297 | up20180642 | |
1016 | 305 | up20180642 | rectangle_dtor(r_buffer); |
1017 | text_dtor (t_buffer); |
||
1018 | 297 | up20180642 | |
1019 | 305 | up20180642 | rectangle_dtor(r_text); |
1020 | for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_dtor(t_text[i]); |
||
1021 | 297 | up20180642 | |
1022 | 305 | up20180642 | nctp_set_processor(NULL);
|
1023 | 298 | up20180642 | |
1024 | 305 | up20180642 | return SUCCESS;
|
1025 | 296 | up20180642 | } |