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