root / proj / src / proj.c @ 308
History | View | Annotate | Download (25.3 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
#include <lcom/proj.h> |
3 |
#include <lcom/liblm.h> |
4 |
#include <math.h> |
5 |
|
6 |
#include "proj_macros.h" |
7 |
#include "proj_func.h" |
8 |
|
9 |
#include "kbc.h" |
10 |
#include "timer.h" |
11 |
#include "keyboard.h" |
12 |
#include "mouse.h" |
13 |
#include "graph.h" |
14 |
#include "menu.h" |
15 |
#include "rtc.h" |
16 |
#include "hltp.h" |
17 |
#include "interrupts_func.h" |
18 |
#include "makecode_map.h" |
19 |
|
20 |
#include "graph.h" |
21 |
#include "rectangle.h" |
22 |
#include "font.h" |
23 |
#include "ent.h" |
24 |
|
25 |
#include "crosshair.h" |
26 |
#include "shooter.h" |
27 |
#include "zombie.h" |
28 |
#include "pistol.h" |
29 |
#include "nothing.h" |
30 |
#include "bullet.h" |
31 |
#include "map1.h" |
32 |
|
33 |
#include "errors.h" |
34 |
|
35 |
#include "list.h" |
36 |
|
37 |
int main(int argc, char* argv[]) { |
38 |
|
39 |
lcf_set_language("EN-US");
|
40 |
|
41 |
lcf_trace_calls("/home/lcom/labs/proj/trace.txt");
|
42 |
|
43 |
lcf_log_output("/home/lcom/labs/proj/output.txt");
|
44 |
|
45 |
if (lcf_start(argc, argv)) return 1; |
46 |
|
47 |
lcf_cleanup(); |
48 |
|
49 |
return 0; |
50 |
} |
51 |
|
52 |
font_t *consolas = NULL;
|
53 |
basic_sprite_t *bsp_crosshair = NULL;
|
54 |
basic_sprite_t *bsp_shooter = NULL;
|
55 |
basic_sprite_t *bsp_zombie = NULL;
|
56 |
basic_sprite_t *bsp_pistol = NULL;
|
57 |
basic_sprite_t *bsp_nothing = NULL;
|
58 |
basic_sprite_t *bsp_bullet = NULL;
|
59 |
map_t *map1 = NULL;
|
60 |
sprite_t *sp_crosshair = NULL;
|
61 |
|
62 |
static int (singleplayer)(void); |
63 |
//static int (multiplayer)(void);
|
64 |
static int (chat)(void); |
65 |
int(proj_main_loop)(int argc, char *argv[]) { |
66 |
|
67 |
int r;
|
68 |
|
69 |
consolas = font_ctor("/home/lcom/labs/proj/media/font/Consolas/xpm2");
|
70 |
if(consolas == NULL){ printf("Failed to load consolas\n"); return 1; } |
71 |
|
72 |
/// subscribe interrupts
|
73 |
if (subscribe_all()) { return 1; } |
74 |
|
75 |
/// initialize graphics
|
76 |
if(graph_init(GRAPH_MODE)){
|
77 |
printf("%s: failed to initalize graphics.\n", __func__);
|
78 |
if (cleanup()) printf("%s: failed to cleanup.\n", __func__); |
79 |
return 1; |
80 |
} |
81 |
|
82 |
/// Load stuff
|
83 |
{ |
84 |
graph_clear_screen(); |
85 |
text_t *txt = text_ctor(consolas, "Loading...");
|
86 |
text_draw(txt); |
87 |
text_dtor(txt); |
88 |
graph_draw(); |
89 |
|
90 |
bsp_crosshair = get_crosshair(); if(bsp_crosshair == NULL) printf("Failed to get crosshair\n"); |
91 |
bsp_shooter = get_shooter (); if(bsp_shooter == NULL) printf("Failed to get shooter\n"); |
92 |
bsp_zombie = get_zombie (); if(bsp_zombie == NULL) printf("Failed to get zombie\n"); |
93 |
bsp_pistol = get_pistol (); if(bsp_pistol == NULL) printf("Failed to get pistol\n"); |
94 |
bsp_nothing = get_nothing (); if(bsp_nothing == NULL) printf("Failed to get nothing\n"); |
95 |
bsp_bullet = get_bullet (); if(bsp_bullet == NULL) printf("Failed to get bullet\n"); |
96 |
map1 = get_map1 (); if(map1 == NULL) printf("Failed to get map1\n"); |
97 |
|
98 |
sp_crosshair = sprite_ctor(bsp_crosshair); if(sp_crosshair == NULL) printf("Failed to get crosshair sprite\n"); |
99 |
} |
100 |
|
101 |
menu_t *main_menu = menu_ctor(consolas); |
102 |
menu_add_item(main_menu, "Single player");
|
103 |
menu_add_item(main_menu, "Multiplayer");
|
104 |
menu_add_item(main_menu, "Chat");
|
105 |
menu_add_item(main_menu, "Exit");
|
106 |
|
107 |
//uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
108 |
uint8_t last_lb = 0;
|
109 |
struct packet pp;
|
110 |
keys_t *keys = get_key_presses(); |
111 |
|
112 |
/// loop stuff
|
113 |
int click = 0; |
114 |
uint32_t int_vector = 0;
|
115 |
int good = true; |
116 |
while (good) {
|
117 |
/* Get a request message. */
|
118 |
if((r = get_interrupts_vector(&int_vector))) return r; |
119 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
120 |
if (int_vector & n) {
|
121 |
interrupt_handler(i); |
122 |
switch (i) {
|
123 |
case TIMER0_IRQ:
|
124 |
|
125 |
graph_clear_screen(); |
126 |
switch(menu_update_state(main_menu, click)){
|
127 |
case -1: break; |
128 |
case 0: singleplayer(); break; //campaign(); break; |
129 |
case 1: break; |
130 |
case 2: chat(); break; |
131 |
case 3: good = false; break; |
132 |
} |
133 |
menu_draw(main_menu); |
134 |
|
135 |
click = 0;
|
136 |
|
137 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
138 |
sprite_draw(sp_crosshair); |
139 |
graph_draw(); |
140 |
|
141 |
break;
|
142 |
case KBC_IRQ:
|
143 |
if ((scancode[0]) == ESC_BREAK_CODE) good = false; |
144 |
case MOUSE_IRQ:
|
145 |
if (counter_mouse_ih >= 3) { |
146 |
mouse_parse_packet(packet_mouse_ih, &pp); |
147 |
update_mouse(&pp); |
148 |
if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
|
149 |
last_lb = keys->lb_pressed; |
150 |
counter_mouse_ih = 0;
|
151 |
} |
152 |
break;
|
153 |
case COM1_IRQ: nctp_ih(); break; |
154 |
} |
155 |
} |
156 |
} |
157 |
} |
158 |
|
159 |
basic_sprite_dtor (bsp_crosshair); bsp_crosshair = NULL;
|
160 |
basic_sprite_dtor (bsp_shooter ); bsp_shooter = NULL;
|
161 |
basic_sprite_dtor (bsp_zombie ); bsp_zombie = NULL;
|
162 |
sprite_dtor (sp_crosshair ); sp_crosshair = NULL;
|
163 |
basic_sprite_dtor (bsp_pistol ); bsp_pistol = NULL;
|
164 |
basic_sprite_dtor (bsp_nothing ); bsp_nothing = NULL;
|
165 |
map_dtor (map1 ); map1 = NULL;
|
166 |
font_dtor (consolas ); consolas = NULL;
|
167 |
|
168 |
// Unsubscribe interrupts
|
169 |
if (unsubscribe_all()) {
|
170 |
if (cleanup())
|
171 |
printf("%s: failed to cleanup.\n", __func__);
|
172 |
return 1; |
173 |
} |
174 |
|
175 |
if (cleanup()) {
|
176 |
printf("%s: failed to cleanup.\n", __func__);
|
177 |
return 1; |
178 |
} |
179 |
|
180 |
return 0; |
181 |
} |
182 |
|
183 |
typedef struct __attribute__((packed)) { |
184 |
// player 1
|
185 |
double player1_x;
|
186 |
double player1_y;
|
187 |
double player1_health;
|
188 |
double player1_current_health;
|
189 |
|
190 |
// player 2
|
191 |
double player2_x;
|
192 |
double player2_y;
|
193 |
double player2_health;
|
194 |
double player2_current_health;
|
195 |
|
196 |
// bullets
|
197 |
size_t no_bullets; |
198 |
double *bullets_x;
|
199 |
double *bullets_y;
|
200 |
double *bullets_vx;
|
201 |
double *bullets_vy;
|
202 |
bool *bullet_shooter; // 0 for player 1, otherwise 1 for player 2 |
203 |
} host_info; |
204 |
|
205 |
typedef struct __attribute__((packed)) { |
206 |
keys_t client_keys_pressed; |
207 |
int32_t client_mouse_x; |
208 |
int32_t client_mouse_y; |
209 |
size_t bullets_shot; |
210 |
double *bullets_x;
|
211 |
double *bullets_y;
|
212 |
} client_info; |
213 |
/*
|
214 |
static void host_to_client_process(const uint8_t *p, const size_t sz) {
|
215 |
|
216 |
}
|
217 |
|
218 |
static void client_to_host_process(const uint8_t *p, const size_t sz) {
|
219 |
}
|
220 |
|
221 |
static int (multiplayer)(void) {
|
222 |
|
223 |
//int r;
|
224 |
|
225 |
ent_set_scale(DEFAULT_SCALE);
|
226 |
//text_timer_t *in_game_timer = timer_ctor(consolas);
|
227 |
|
228 |
list_t *shooter_list = list_ctor();
|
229 |
|
230 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n");
|
231 |
gunner_set_spawn(shooter1, 75, 75);
|
232 |
|
233 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter2 == NULL) printf("Failed to get shooter2\n");
|
234 |
gunner_set_spawn(shooter2, 975, 75);
|
235 |
|
236 |
list_insert(shooter_list, list_end(shooter_list), shooter1);
|
237 |
list_insert(shooter_list, list_end(shooter_list), shooter2);
|
238 |
|
239 |
do {
|
240 |
get_random_spawn(map1, shooter1, shooter_list);
|
241 |
get_random_spawn(map1, shooter2, shooter_list);
|
242 |
} while (distance_gunners(shooter1, shooter2) < 700);
|
243 |
|
244 |
list_t *bullet_list = list_ctor();
|
245 |
|
246 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0,
|
247 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0);
|
248 |
|
249 |
//uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
250 |
uint8_t last_lb = 0;
|
251 |
struct packet pp;
|
252 |
keys_t *keys = get_key_presses();
|
253 |
|
254 |
/// loop stuff
|
255 |
uint32_t int_vector = 0;
|
256 |
int good = true;
|
257 |
|
258 |
// incomplete
|
259 |
|
260 |
return 0;
|
261 |
}*/
|
262 |
|
263 |
static int (campaign)(void); |
264 |
static int (zombies)(void); |
265 |
static int (singleplayer)(void) { |
266 |
|
267 |
int r;
|
268 |
|
269 |
menu_t *main_menu = menu_ctor(consolas); |
270 |
menu_add_item(main_menu, "Campaign");
|
271 |
menu_add_item(main_menu, "Zombies");
|
272 |
menu_add_item(main_menu, "Back");
|
273 |
|
274 |
//uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
275 |
uint8_t last_lb = 0;
|
276 |
struct packet pp;
|
277 |
keys_t *keys = get_key_presses(); |
278 |
|
279 |
/// loop stuff
|
280 |
int click = 0; |
281 |
uint32_t int_vector = 0;
|
282 |
int good = true; |
283 |
while (good) {
|
284 |
/* Get a request message. */
|
285 |
if((r = get_interrupts_vector(&int_vector))) return r; |
286 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
287 |
if (int_vector & n) {
|
288 |
interrupt_handler(i); |
289 |
switch (i) {
|
290 |
case TIMER0_IRQ:
|
291 |
|
292 |
graph_clear_screen(); |
293 |
switch(menu_update_state(main_menu, click)){
|
294 |
case -1: break; |
295 |
case 0: campaign(); break; |
296 |
case 1: zombies(); break; |
297 |
case 2: good = false; break; |
298 |
} |
299 |
menu_draw(main_menu); |
300 |
|
301 |
click = 0;
|
302 |
|
303 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
304 |
sprite_draw(sp_crosshair); |
305 |
graph_draw(); |
306 |
|
307 |
break;
|
308 |
case KBC_IRQ:
|
309 |
if ((scancode[0]) == ESC_BREAK_CODE) good = false; |
310 |
case MOUSE_IRQ:
|
311 |
if (counter_mouse_ih >= 3) { |
312 |
mouse_parse_packet(packet_mouse_ih, &pp); |
313 |
update_mouse(&pp); |
314 |
if (!click) click = last_lb ^ keys->lb_pressed && keys->lb_pressed;
|
315 |
last_lb = keys->lb_pressed; |
316 |
counter_mouse_ih = 0;
|
317 |
} |
318 |
break;
|
319 |
case COM1_IRQ: nctp_ih(); break; |
320 |
} |
321 |
} |
322 |
} |
323 |
} |
324 |
|
325 |
return 0; |
326 |
} |
327 |
|
328 |
static int (campaign)(void){ |
329 |
|
330 |
int r;
|
331 |
|
332 |
ent_set_scale(DEFAULT_SCALE); |
333 |
text_timer_t *in_game_timer = timer_ctor(consolas); |
334 |
|
335 |
list_t *shooter_list = list_ctor(); |
336 |
|
337 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
338 |
gunner_set_spawn(shooter1, 75, 75); |
339 |
gunner_set_pos(shooter1, 75, 75); |
340 |
|
341 |
gunner_t *shooter2 = gunner_ctor(bsp_shooter, bsp_nothing, gunner_player, 2);
|
342 |
gunner_set_spawn(shooter2, 975, 75); |
343 |
gunner_set_pos(shooter2, 775, 75); |
344 |
|
345 |
list_insert(shooter_list, list_end(shooter_list), shooter1); |
346 |
list_insert(shooter_list, list_end(shooter_list), shooter2); |
347 |
|
348 |
list_t *bullet_list = list_ctor(); |
349 |
|
350 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
351 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
352 |
|
353 |
//uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
354 |
uint8_t last_lb = 0;
|
355 |
struct packet pp;
|
356 |
keys_t *keys = get_key_presses(); |
357 |
|
358 |
/// loop stuff
|
359 |
uint32_t int_vector = 0;
|
360 |
int good = true; |
361 |
while (good) {
|
362 |
/* Get a request message. */
|
363 |
if((r = get_interrupts_vector(&int_vector))) return r; |
364 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
365 |
if (int_vector & n) {
|
366 |
interrupt_handler(i); |
367 |
switch (i) {
|
368 |
case TIMER0_IRQ:
|
369 |
|
370 |
if (no_interrupts % 60 == 0) timer_update(in_game_timer); |
371 |
update_movement(map1, shooter1, keys, shooter_list); |
372 |
|
373 |
update_game_state(map1, shooter_list, bullet_list); |
374 |
|
375 |
//update_scale();
|
376 |
double angle = get_mouse_angle(shooter1);
|
377 |
gunner_set_angle(shooter1, angle - M_PI_2); |
378 |
|
379 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
380 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
381 |
|
382 |
graph_clear_screen(); |
383 |
map_draw (map1); |
384 |
bullet_draw_list(bullet_list); |
385 |
gunner_draw_list(shooter_list); |
386 |
|
387 |
text_draw(in_game_timer->text); |
388 |
|
389 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
390 |
sprite_draw(sp_crosshair); |
391 |
graph_draw(); |
392 |
|
393 |
break;
|
394 |
case KBC_IRQ:
|
395 |
if ((scancode[0]) == ESC_BREAK_CODE) { |
396 |
good = false;
|
397 |
// reset game
|
398 |
while(list_size(bullet_list) > 0){ |
399 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
400 |
bullet_dtor(p); |
401 |
} |
402 |
list_node_t *it = list_begin(shooter_list); |
403 |
while (it != list_end(shooter_list)) {
|
404 |
gunner_t *p = *(gunner_t**)list_node_val(it); |
405 |
get_random_spawn(map1, p, shooter_list); |
406 |
gunner_set_curr_health(p, gunner_get_health(p)); |
407 |
it = list_node_next(it); |
408 |
} |
409 |
timer_reset(in_game_timer); |
410 |
} |
411 |
break;
|
412 |
case MOUSE_IRQ:
|
413 |
if (counter_mouse_ih >= 3) { |
414 |
mouse_parse_packet(packet_mouse_ih, &pp); |
415 |
update_mouse(&pp); |
416 |
if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
|
417 |
shoot_bullet(shooter1, bullet_list, bsp_bullet); |
418 |
last_lb = keys->lb_pressed; |
419 |
counter_mouse_ih = 0;
|
420 |
|
421 |
} |
422 |
break;
|
423 |
case COM1_IRQ: nctp_ih(); break; |
424 |
} |
425 |
} |
426 |
} |
427 |
} |
428 |
|
429 |
while(list_size(shooter_list) > 0){ |
430 |
gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
431 |
gunner_dtor(p); |
432 |
} |
433 |
if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
434 |
|
435 |
while(list_size(bullet_list) > 0){ |
436 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
437 |
bullet_dtor(p); |
438 |
} |
439 |
if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
440 |
|
441 |
timer_dtor(in_game_timer); in_game_timer = NULL;
|
442 |
|
443 |
return SUCCESS;
|
444 |
} |
445 |
|
446 |
#define ZOMBIES_NUM 5 |
447 |
#define ZOMBIE_HEALTH_FACTOR 1.1 |
448 |
|
449 |
static int (zombies)(void){ |
450 |
|
451 |
int r;
|
452 |
|
453 |
ent_set_scale(DEFAULT_SCALE); |
454 |
text_timer_t *in_game_timer = timer_ctor(consolas); |
455 |
|
456 |
list_t *shooter_list = list_ctor(); |
457 |
|
458 |
gunner_t *shooter1 = gunner_ctor(bsp_shooter, bsp_pistol, gunner_player, 1); if(shooter1 == NULL) printf("Failed to get shooter1\n"); |
459 |
gunner_set_spawn(shooter1, 980, 790); |
460 |
gunner_set_pos(shooter1, 980, 790); |
461 |
|
462 |
list_insert(shooter_list, list_end(shooter_list), shooter1); |
463 |
|
464 |
list_t *bullet_list = list_ctor(); |
465 |
|
466 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
467 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
468 |
|
469 |
//uint32_t refresh_count_value = sys_hz() / REFRESH_RATE;
|
470 |
uint8_t last_lb = 0;
|
471 |
struct packet pp;
|
472 |
keys_t *keys = get_key_presses(); |
473 |
|
474 |
/// loop stuff
|
475 |
uint32_t int_vector = 0;
|
476 |
int good = true; |
477 |
int dead = false; |
478 |
|
479 |
int health = 50; |
480 |
|
481 |
while (good && !dead) {
|
482 |
/* Get a request message. */
|
483 |
if((r = get_interrupts_vector(&int_vector))) return r; |
484 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
485 |
if (int_vector & n) {
|
486 |
interrupt_handler(i); |
487 |
switch (i) {
|
488 |
case TIMER0_IRQ:
|
489 |
if (no_interrupts % 60 == 0) timer_update(in_game_timer); |
490 |
|
491 |
update_movement(map1, shooter1, keys, shooter_list); |
492 |
|
493 |
update_game_state(map1, shooter_list, bullet_list); |
494 |
|
495 |
if(list_find(shooter_list, shooter1) == list_end(shooter_list)){
|
496 |
good = false;
|
497 |
dead = true;
|
498 |
break;
|
499 |
} |
500 |
|
501 |
double angle = get_mouse_angle(shooter1);
|
502 |
gunner_set_angle(shooter1, angle - M_PI_2); |
503 |
|
504 |
ent_set_origin(gunner_get_x(shooter1)-ent_get_XLength()/2.0, |
505 |
gunner_get_y(shooter1)-ent_get_YLength()/2.0); |
506 |
|
507 |
while(list_size(shooter_list) < ZOMBIES_NUM){
|
508 |
gunner_t *zombie = gunner_ctor(bsp_zombie, bsp_nothing, gunner_melee | gunner_follow, 3);
|
509 |
gunner_set_health(zombie, health); |
510 |
gunner_set_curr_health(zombie, health); |
511 |
health *= ZOMBIE_HEALTH_FACTOR; |
512 |
get_random_spawn(map1, zombie, shooter_list); |
513 |
list_push_back(shooter_list, zombie); |
514 |
} |
515 |
|
516 |
graph_clear_screen(); |
517 |
map_draw (map1); |
518 |
bullet_draw_list(bullet_list); |
519 |
gunner_draw_list(shooter_list); |
520 |
|
521 |
text_draw(in_game_timer->text); |
522 |
|
523 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
524 |
sprite_draw(sp_crosshair); |
525 |
graph_draw(); |
526 |
|
527 |
break;
|
528 |
case KBC_IRQ:
|
529 |
if ((scancode[0]) == ESC_BREAK_CODE) { |
530 |
good = false;
|
531 |
} |
532 |
break;
|
533 |
case MOUSE_IRQ:
|
534 |
if (counter_mouse_ih >= 3) { |
535 |
mouse_parse_packet(packet_mouse_ih, &pp); |
536 |
update_mouse(&pp); |
537 |
if (last_lb ^ keys->lb_pressed && keys->lb_pressed)
|
538 |
shoot_bullet(shooter1, bullet_list, bsp_bullet); |
539 |
last_lb = keys->lb_pressed; |
540 |
counter_mouse_ih = 0;
|
541 |
|
542 |
} |
543 |
break;
|
544 |
case COM1_IRQ: nctp_ih(); break; |
545 |
} |
546 |
} |
547 |
} |
548 |
} |
549 |
|
550 |
while(list_size(shooter_list) > 0){ |
551 |
gunner_t *p = list_erase(shooter_list, list_begin(shooter_list)); |
552 |
gunner_dtor(p); |
553 |
} |
554 |
if(list_dtor(shooter_list)) printf("COULD NOT DESTRUCT SHOOTER LIST\n"); |
555 |
|
556 |
while(list_size(bullet_list) > 0){ |
557 |
bullet_t *p = (bullet_t*)list_erase(bullet_list, list_begin(bullet_list)); |
558 |
bullet_dtor(p); |
559 |
} |
560 |
if(list_dtor(bullet_list)) printf("COULD NOT DESTRUCT BULLET LIST\n"); |
561 |
|
562 |
if(dead){
|
563 |
printf("YOU DIED\n");
|
564 |
} |
565 |
|
566 |
timer_dtor(in_game_timer); in_game_timer = NULL;
|
567 |
|
568 |
return SUCCESS;
|
569 |
} |
570 |
|
571 |
#define CHAT_MAX_SIZE 75 |
572 |
#define CHAT_MAX_NUM 19 |
573 |
text_t *t_text[CHAT_MAX_NUM] = {NULL};
|
574 |
rectangle_t *r_text = NULL;
|
575 |
static void chat_process(const uint8_t *p, const size_t sz){ |
576 |
char buffer2[CHAT_MAX_NUM+3]; |
577 |
void *dest = NULL; |
578 |
hltp_type tp = hltp_interpret(p, sz, &dest); |
579 |
switch(tp){
|
580 |
case hltp_type_string:
|
581 |
strcpy(buffer2, dest); |
582 |
strncat(buffer2, " <", 2); |
583 |
for(size_t i = CHAT_MAX_NUM-1; i; --i) |
584 |
text_set_text(t_text[i], text_get_string(t_text[i-1]));
|
585 |
text_set_text(t_text[0], buffer2);
|
586 |
for(size_t i = 0; i < CHAT_MAX_NUM; ++i){ |
587 |
if(text_get_string(t_text[i])[0] == '>'){ |
588 |
text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
|
589 |
text_set_halign(t_text[i], text_halign_left); |
590 |
}else{
|
591 |
text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
|
592 |
text_set_halign(t_text[i], text_halign_right); |
593 |
} |
594 |
} |
595 |
break;
|
596 |
default: break; |
597 |
} |
598 |
} |
599 |
static int (chat)(void){ |
600 |
int r;
|
601 |
|
602 |
nctp_dump(); |
603 |
nctp_set_processor(chat_process); |
604 |
|
605 |
struct packet pp;
|
606 |
|
607 |
char buffer[CHAT_MAX_SIZE] = ""; |
608 |
rectangle_t *r_buffer = NULL; {
|
609 |
r_buffer = rectangle_ctor(0,0,900,70); |
610 |
rectangle_set_pos(r_buffer, graph_get_XRes()/2 -rectangle_get_w(r_buffer)/2, |
611 |
graph_get_YRes()*0.87-rectangle_get_h(r_buffer)/2); |
612 |
rectangle_set_fill_color (r_buffer, GRAPH_BLACK); |
613 |
rectangle_set_outline_width(r_buffer, 2);
|
614 |
rectangle_set_outline_color(r_buffer, GRAPH_WHITE); |
615 |
rectangle_set_fill_trans(r_buffer, GRAPH_TRANSPARENT); |
616 |
} |
617 |
text_t *t_buffer = NULL; {
|
618 |
t_buffer = text_ctor(consolas, "");
|
619 |
text_set_pos(t_buffer, rectangle_get_x(r_buffer)+50,
|
620 |
rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)/2);
|
621 |
text_set_halign(t_buffer, text_halign_left); |
622 |
text_set_valign(t_buffer, text_valign_center); |
623 |
text_set_color (t_buffer, TEXT_COLOR); |
624 |
} |
625 |
text_t *t_size = NULL; {
|
626 |
t_size = text_ctor(consolas, "");
|
627 |
text_set_pos(t_size, rectangle_get_x(r_buffer)+rectangle_get_w(r_buffer)-5,
|
628 |
rectangle_get_y(r_buffer)+rectangle_get_h(r_buffer)-5);
|
629 |
text_set_halign(t_size, text_halign_right); |
630 |
text_set_valign(t_size, text_valign_bottom); |
631 |
text_set_color (t_size, TEXT_COLOR); |
632 |
text_set_size (t_size, 18);
|
633 |
char buffer2[20]; |
634 |
sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
|
635 |
text_set_text(t_size, buffer2); |
636 |
} |
637 |
|
638 |
/** r_text */ {
|
639 |
r_text = rectangle_ctor(0,0,900,550); |
640 |
rectangle_set_pos(r_text, graph_get_XRes()/2 -rectangle_get_w(r_buffer)/2, |
641 |
graph_get_YRes()*0.09); |
642 |
rectangle_set_fill_color (r_text, GRAPH_BLACK); |
643 |
rectangle_set_outline_width(r_text, 2);
|
644 |
rectangle_set_outline_color(r_text, GRAPH_WHITE); |
645 |
rectangle_set_fill_trans(r_text, GRAPH_TRANSPARENT); |
646 |
} |
647 |
/** t_text */ {
|
648 |
for(size_t i = 0; i < CHAT_MAX_NUM; ++i){ |
649 |
t_text[i] = text_ctor(consolas, " ");
|
650 |
text_set_pos(t_text[i], rectangle_get_x(r_text)+50,
|
651 |
rectangle_get_y(r_text)+rectangle_get_h(r_text)-30-25*i); |
652 |
text_set_halign(t_text[i], text_halign_left); |
653 |
text_set_valign(t_text[i], text_valign_bottom); |
654 |
text_set_color (t_text[i], TEXT_COLOR); |
655 |
} |
656 |
} |
657 |
|
658 |
/// loop stuff
|
659 |
uint32_t int_vector = 0;
|
660 |
int good = true; |
661 |
while (good) {
|
662 |
/* Get a request message. */
|
663 |
if((r = get_interrupts_vector(&int_vector))) return r; |
664 |
for (uint32_t i = 0, n = 1; i < 32; i++, n <<= 1) { |
665 |
if (int_vector & n) {
|
666 |
interrupt_handler(i); |
667 |
switch (i) {
|
668 |
case TIMER0_IRQ:
|
669 |
graph_clear_screen(); |
670 |
sprite_set_pos(sp_crosshair, *get_mouse_X(), *get_mouse_Y()); |
671 |
|
672 |
rectangle_draw(r_buffer); |
673 |
text_draw(t_buffer); |
674 |
text_draw(t_size); |
675 |
|
676 |
rectangle_draw(r_text); |
677 |
for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_draw(t_text[i]); |
678 |
|
679 |
sprite_draw(sp_crosshair); |
680 |
graph_draw(); |
681 |
break;
|
682 |
case KBC_IRQ:
|
683 |
if (scancode[0] == ESC_BREAK_CODE) good = false; |
684 |
else if (scancode[0] == ENTER_MAKE_CODE) { |
685 |
hltp_send_string(buffer); |
686 |
char buffer2[CHAT_MAX_SIZE+3] = "> "; |
687 |
strncat(buffer2, buffer, strlen(buffer)); |
688 |
for(size_t i = CHAT_MAX_NUM-1; i; --i) |
689 |
text_set_text(t_text[i], text_get_string(t_text[i-1]));
|
690 |
text_set_text(t_text[0], buffer2);
|
691 |
for(size_t i = 0; i < CHAT_MAX_NUM; ++i){ |
692 |
if(text_get_string(t_text[i])[0] == '>'){ |
693 |
text_set_pos(t_text[i], rectangle_get_x(r_text)+50, text_get_y(t_text[i]));
|
694 |
text_set_halign(t_text[i], text_halign_left); |
695 |
}else{
|
696 |
text_set_pos(t_text[i], rectangle_get_x(r_text)+rectangle_get_w(r_text)-50, text_get_y(t_text[i]));
|
697 |
text_set_halign(t_text[i], text_halign_right); |
698 |
} |
699 |
} |
700 |
buffer[0] = '\0'; |
701 |
} else if(scancode[0] == BACKSPACE_MAKE_CODE){ |
702 |
buffer[strlen(buffer)-1] = '\0'; |
703 |
} else {
|
704 |
char c = map_makecode(scancode[0]); |
705 |
if (c == ERROR_CODE) break; |
706 |
if(strlen(buffer) < CHAT_MAX_SIZE) strncat(buffer, &c, 1); |
707 |
else printf("Char limit exceeded\n"); |
708 |
} |
709 |
text_set_text(t_buffer, buffer); |
710 |
char buffer2[20]; |
711 |
sprintf(buffer2, "%d/%d", strlen(buffer), CHAT_MAX_SIZE);
|
712 |
text_set_text(t_size, buffer2); |
713 |
case MOUSE_IRQ:
|
714 |
if (counter_mouse_ih >= 3) { |
715 |
mouse_parse_packet(packet_mouse_ih, &pp); |
716 |
update_mouse(&pp); |
717 |
counter_mouse_ih = 0;
|
718 |
} |
719 |
break;
|
720 |
case COM1_IRQ: nctp_ih(); break; |
721 |
} |
722 |
} |
723 |
} |
724 |
} |
725 |
|
726 |
rectangle_dtor(r_buffer); |
727 |
text_dtor (t_buffer); |
728 |
|
729 |
rectangle_dtor(r_text); |
730 |
for(size_t i = 0; i < CHAT_MAX_NUM; ++i) text_dtor(t_text[i]); |
731 |
|
732 |
nctp_set_processor(NULL);
|
733 |
|
734 |
return SUCCESS;
|
735 |
} |