Revision 320
multiplayer almost working, serial data not being transmitted?
proj_func.c | ||
---|---|---|
27 | 27 |
|
28 | 28 |
static keys_t key_presses; |
29 | 29 |
|
30 |
host_info_t* host_info_ctor(gunner_t *host, gunner_t *remote) { |
|
31 |
host_info_t *ret = (host_info_t*)malloc(sizeof(host_info_t)); |
|
32 |
if (ret == NULL) return ret; |
|
33 |
|
|
34 |
ret->host_x = gunner_get_x (host); |
|
35 |
ret->host_y = gunner_get_y (host); |
|
36 |
ret->host_angle = gunner_get_angle (host); |
|
37 |
ret->host_health = gunner_get_health (host); |
|
38 |
ret->host_current_health = gunner_get_curr_health(host); |
|
39 |
|
|
40 |
// remote |
|
41 |
ret->remote_x = gunner_get_x (remote); |
|
42 |
ret->remote_y = gunner_get_y (remote); |
|
43 |
ret->remote_angle = gunner_get_angle (remote); |
|
44 |
ret->remote_health = gunner_get_health (remote); |
|
45 |
ret->remote_current_health = gunner_get_curr_health(remote); |
|
46 |
|
|
47 |
ret->no_bullets = 0; |
|
48 |
|
|
49 |
return ret; |
|
50 |
} |
|
51 |
|
|
30 | 52 |
void host_info_dtor(host_info_t *p) { |
31 | 53 |
if (p==NULL) return; |
32 | 54 |
|
... | ... | |
43 | 65 |
free(p); |
44 | 66 |
} |
45 | 67 |
|
68 |
remote_info_t* remote_info_ctor() { |
|
69 |
remote_info_t *ret = (remote_info_t*)malloc(sizeof(remote_info_t)); |
|
70 |
if (ret == NULL) return ret; |
|
71 |
|
|
72 |
memset(&(ret->remote_keys_pressed), 0, sizeof(keys_t)); |
|
73 |
|
|
74 |
ret->remote_angle = 0; |
|
75 |
|
|
76 |
return ret; |
|
77 |
} |
|
78 |
|
|
46 | 79 |
void remote_info_dtor(remote_info_t *p) { |
47 | 80 |
if (p==NULL) return; |
81 |
free(p); |
|
82 |
} |
|
48 | 83 |
|
49 |
if ((p->bullets_x) != NULL){ free(p->bullets_x); p->bullets_x = NULL; } |
|
84 |
bullet_info_t* bullet_info_ctor() { |
|
85 |
bullet_info_t *ret = (bullet_info_t*)malloc(sizeof(bullet_info_t)); |
|
86 |
if (ret == NULL) return ret; |
|
50 | 87 |
|
51 |
if ((p->bullets_y) != NULL){ free(p->bullets_y); p->bullets_y = NULL; }
|
|
88 |
ret->new_bullet = false;
|
|
52 | 89 |
|
53 |
if ((p->bullets_angle) != NULL){ free(p->bullets_angle); p->bullets_angle = NULL; } |
|
90 |
return ret; |
|
91 |
} |
|
54 | 92 |
|
93 |
void bullet_info_dtor(bullet_info_t *p) { |
|
94 |
if (p == NULL) return; |
|
55 | 95 |
free(p); |
56 | 96 |
} |
57 | 97 |
|
... | ... | |
278 | 318 |
return atan2(gunner_get_y_screen(p) - mouse_y, mouse_x - gunner_get_x_screen(p)); |
279 | 319 |
} |
280 | 320 |
|
321 |
void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote, list_t *bullet_list) { |
|
322 |
// host |
|
323 |
p->host_x = gunner_get_x (host); |
|
324 |
p->host_y = gunner_get_y (host); |
|
325 |
p->host_angle = gunner_get_angle (host); |
|
326 |
p->host_health = gunner_get_health (host); |
|
327 |
p->host_current_health = gunner_get_curr_health(host); |
|
328 |
|
|
329 |
// remote |
|
330 |
p->remote_x = gunner_get_x (remote); |
|
331 |
p->remote_y = gunner_get_y (remote); |
|
332 |
p->remote_angle = gunner_get_angle (remote); |
|
333 |
p->remote_health = gunner_get_health (remote); |
|
334 |
p->remote_current_health = gunner_get_curr_health(remote); |
|
335 |
|
|
336 |
// bullets |
|
337 |
size_t sz = list_size(bullet_list); |
|
338 |
p->no_bullets = sz; |
|
339 |
p->bullets_x = (double*)realloc(p->bullets_x , sz * sizeof(double)); |
|
340 |
p->bullets_y = (double*)realloc(p->bullets_y , sz * sizeof(double)); |
|
341 |
p->bullets_vx = (double*)realloc(p->bullets_vx , sz * sizeof(double)); |
|
342 |
p->bullets_vy = (double*)realloc(p->bullets_vy , sz * sizeof(double)); |
|
343 |
p->bullets_shooter = (bool*) realloc(p->bullets_shooter , sz * sizeof(bool )); |
|
344 |
|
|
345 |
list_node_t *it = list_begin(bullet_list); |
|
346 |
size_t i = 0; |
|
347 |
while (it != list_end(bullet_list)) { |
|
348 |
bullet_t *bullet = *list_node_val(it); |
|
349 |
p->bullets_x [i] = bullet_get_x (bullet); |
|
350 |
p->bullets_y [i] = bullet_get_y (bullet); |
|
351 |
p->bullets_vx [i] = bullet_get_vx (bullet); |
|
352 |
p->bullets_vy [i] = bullet_get_vy (bullet); |
|
353 |
p->bullets_shooter [i] = gunner_get_team(bullet_get_shooter(bullet)) != gunner_get_team(host); |
|
354 |
it = list_node_next(it); |
|
355 |
i++; |
|
356 |
} |
|
357 |
} |
|
358 |
|
|
359 |
void build_remote_structure(remote_info_t *p, keys_t *keys, double angle) { |
|
360 |
memcpy(&(p->remote_keys_pressed), keys, sizeof(keys_t)); |
|
361 |
p->remote_angle = angle; |
|
362 |
} |
|
363 |
|
|
281 | 364 |
text_timer_t* (timer_ctor)(const font_t *fnt){ |
282 | 365 |
if(fnt == NULL) return NULL; |
283 | 366 |
text_timer_t *ret = malloc(sizeof(timer_t)); |
Also available in: Unified diff