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