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