Revision 345
reorganizing
proj_func.c | ||
---|---|---|
26 | 26 |
} |
27 | 27 |
|
28 | 28 |
static keys_t key_presses; |
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 = (int16_t)gunner_get_x (host); |
|
35 |
ret->host_y = (int16_t)gunner_get_y (host); |
|
36 |
ret->host_angle = (int16_t)gunner_get_angle (host); |
|
37 |
ret->host_health = (int16_t)gunner_get_health (host); |
|
38 |
ret->host_current_health = (int16_t)gunner_get_curr_health(host); |
|
39 |
|
|
40 |
// remote |
|
41 |
ret->remote_x = (int16_t)gunner_get_x (remote); |
|
42 |
ret->remote_y = (int16_t)gunner_get_y (remote); |
|
43 |
ret->remote_angle = (int16_t)gunner_get_angle (remote); |
|
44 |
ret->remote_health = (int16_t)gunner_get_health (remote); |
|
45 |
ret->remote_current_health = (int16_t)gunner_get_curr_health(remote); |
|
46 |
|
|
47 |
//ret->no_bullets = 0; |
|
48 |
|
|
49 |
return ret; |
|
50 |
} |
|
51 |
|
|
52 |
void host_info_dtor(host_info_t *p) { |
|
53 |
if (p==NULL) return; |
|
54 |
/* |
|
55 |
if ((p->bullets_x) != NULL){ free(p->bullets_x); p->bullets_x = NULL; } |
|
56 |
|
|
57 |
if ((p->bullets_y) != NULL){ free(p->bullets_y); p->bullets_y = NULL; } |
|
58 |
|
|
59 |
if ((p->bullets_vx) != NULL){ free(p->bullets_vx); p->bullets_vx = NULL; } |
|
60 |
|
|
61 |
if ((p->bullets_vy) != NULL){ free(p->bullets_vy); p->bullets_vy = NULL; } |
|
62 |
|
|
63 |
if ((p->bullets_shooter) != NULL){ free(p->bullets_shooter); p->bullets_shooter = NULL; } |
|
64 |
*/ |
|
65 |
free(p); |
|
66 |
} |
|
67 |
|
|
68 |
remote_info_t* remote_info_ctor(void) { |
|
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 |
|
|
79 |
void remote_info_dtor(remote_info_t *p) { |
|
80 |
if (p==NULL) return; |
|
81 |
free(p); |
|
82 |
} |
|
83 |
|
|
84 |
bullet_info_t* bullet_info_ctor(void) { |
|
85 |
bullet_info_t *ret = (bullet_info_t*)malloc(sizeof(bullet_info_t)); |
|
86 |
if (ret == NULL) return ret; |
|
87 |
|
|
88 |
ret->new_bullet = false; |
|
89 |
|
|
90 |
return ret; |
|
91 |
} |
|
92 |
|
|
93 |
void bullet_info_dtor(bullet_info_t *p) { |
|
94 |
if (p == NULL) return; |
|
95 |
free(p); |
|
96 |
} |
|
97 |
|
|
98 | 29 |
void update_key_presses(void) { |
99 | 30 |
if (keyboard_get_size() == 1) { |
100 | 31 |
switch(keyboard_get_scancode()[0]) { |
... | ... | |
115 | 46 |
} |
116 | 47 |
} |
117 | 48 |
} |
49 |
keys_t* (get_key_presses)(void) { |
|
50 |
return &key_presses; |
|
51 |
} |
|
118 | 52 |
|
53 |
static int16_t mouse_x = 0, mouse_y = 0; |
|
54 |
void (update_mouse)(struct packet *p) { |
|
55 |
mouse_x = max_16(0, mouse_x + p->delta_x); |
|
56 |
mouse_x = min_16(mouse_x, (int16_t)graph_get_XRes() - 1); |
|
57 |
|
|
58 |
mouse_y = max_16(0, mouse_y - p->delta_y); |
|
59 |
mouse_y = min_16(mouse_y, (int16_t)graph_get_YRes() - 1); |
|
60 |
|
|
61 |
key_presses.lb_pressed = p->lb; |
|
62 |
} |
|
63 |
int16_t* get_mouse_X(void) { return &mouse_x; } |
|
64 |
int16_t* get_mouse_Y(void) { return &mouse_y; } |
|
65 |
double get_mouse_angle(gunner_t *p) { |
|
66 |
return atan2(gunner_get_y_screen(p) - mouse_y, mouse_x - gunner_get_x_screen(p)); |
|
67 |
} |
|
68 |
|
|
119 | 69 |
void update_movement(map_t *map, gunner_t *p, keys_t *keys, list_t *shooter_list) { |
120 | 70 |
/** Player movement */{ |
121 | 71 |
int ver_mov = keys->s_pressed - keys->w_pressed; |
... | ... | |
183 | 133 |
} |
184 | 134 |
} |
185 | 135 |
|
136 |
void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l) { |
|
137 |
uint16_t w = map_get_width(map), h = map_get_height(map); |
|
138 |
double x, y; |
|
139 |
|
|
140 |
while(true){ |
|
141 |
x = rand() % w; |
|
142 |
y = rand() % h; |
|
143 |
gunner_set_pos(p, x, y); |
|
144 |
if(map_collides_gunner(map, p)) continue; |
|
145 |
int collides = false; |
|
146 |
list_node_t *it = list_begin(l); |
|
147 |
while(it != list_end(l)){ |
|
148 |
if(gunner_collides_gunner(p, *list_node_val(it))){ |
|
149 |
collides = true; |
|
150 |
break; |
|
151 |
} |
|
152 |
it = list_node_next(it); |
|
153 |
} |
|
154 |
if(!collides) return; |
|
155 |
} |
|
156 |
} |
|
157 |
|
|
158 |
void update_scale(void) { |
|
159 |
static uint8_t last_plus = 0, last_minus = 0; |
|
160 |
if (key_presses.ctrl_pressed) { |
|
161 |
if (key_presses.plus_pressed && !last_plus) { |
|
162 |
double scale = ent_get_scale(); |
|
163 |
scale *= 1.1; |
|
164 |
if (scale <= MAX_SCALE) ent_set_scale(scale); |
|
165 |
} |
|
166 |
else if (key_presses.minus_pressed && !last_minus) { |
|
167 |
double scale = ent_get_scale(); |
|
168 |
scale /= 1.1; |
|
169 |
if (scale >= MIN_SCALE) ent_set_scale(scale); |
|
170 |
} |
|
171 |
|
|
172 |
//printf("SCALE: %d\n", (int)(ent_get_scale()*1000)); |
|
173 |
} |
|
174 |
|
|
175 |
last_plus = key_presses.plus_pressed; |
|
176 |
last_minus = key_presses.minus_pressed; |
|
177 |
} |
|
178 |
|
|
186 | 179 |
void (shoot_bullet)(const gunner_t *shooter, list_t *bullet_list, const basic_sprite_t *bsp_bullet) { |
187 | 180 |
double angle = gunner_get_angle(shooter); |
188 | 181 |
double vx = -BULLET_SPEED * fm_sin(angle); |
... | ... | |
251 | 244 |
} |
252 | 245 |
} |
253 | 246 |
|
254 |
void update_scale(void) { |
|
255 |
static uint8_t last_plus = 0, last_minus = 0; |
|
256 |
if (key_presses.ctrl_pressed) { |
|
257 |
if (key_presses.plus_pressed && !last_plus) { |
|
258 |
double scale = ent_get_scale(); |
|
259 |
scale *= 1.1; |
|
260 |
if (scale <= MAX_SCALE) ent_set_scale(scale); |
|
261 |
} |
|
262 |
else if (key_presses.minus_pressed && !last_minus) { |
|
263 |
double scale = ent_get_scale(); |
|
264 |
scale /= 1.1; |
|
265 |
if (scale >= MIN_SCALE) ent_set_scale(scale); |
|
266 |
} |
|
247 |
text_timer_t* (text_timer_ctor)(const font_t *fnt){ |
|
248 |
if(fnt == NULL) return NULL; |
|
249 |
text_timer_t *ret = malloc(sizeof(timer_t)); |
|
250 |
if (ret == NULL) return NULL; |
|
251 |
ret->time = 0; |
|
252 |
ret->text = text_ctor(fnt, "000s"); |
|
253 |
text_set_color(ret->text, TEXT_COLOR); |
|
254 |
return ret; |
|
255 |
} |
|
256 |
void (text_timer_update)(text_timer_t *p){ |
|
257 |
if (p->time >= 999) return; |
|
258 |
p->time++; |
|
259 |
char buffer[100]; |
|
260 |
sprintf(buffer, "%03ds", p->time); |
|
261 |
text_set_string(p->text, buffer); |
|
262 |
} |
|
263 |
void (text_timer_reset)(text_timer_t *p){ |
|
264 |
text_set_string(p->text, "000s"); |
|
265 |
} |
|
266 |
void (text_timer_dtor)(text_timer_t *p){ |
|
267 |
if (p == NULL) return; |
|
268 |
text_dtor(p->text); |
|
269 |
free(p); |
|
270 |
} |
|
267 | 271 |
|
268 |
//printf("SCALE: %d\n", (int)(ent_get_scale()*1000)); |
|
269 |
} |
|
272 |
host_info_t* host_info_ctor(gunner_t *host, gunner_t *remote) { |
|
273 |
host_info_t *ret = (host_info_t*)malloc(sizeof(host_info_t)); |
|
274 |
if (ret == NULL) return ret; |
|
270 | 275 |
|
271 |
last_plus = key_presses.plus_pressed; |
|
272 |
last_minus = key_presses.minus_pressed; |
|
273 |
} |
|
276 |
ret->host_x = (int16_t)gunner_get_x (host); |
|
277 |
ret->host_y = (int16_t)gunner_get_y (host); |
|
278 |
ret->host_angle = (int16_t)gunner_get_angle (host); |
|
279 |
ret->host_health = (int16_t)gunner_get_health (host); |
|
280 |
ret->host_current_health = (int16_t)gunner_get_curr_health(host); |
|
274 | 281 |
|
275 |
void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l) { |
|
276 |
uint16_t w = map_get_width(map), h = map_get_height(map); |
|
277 |
double x, y; |
|
282 |
// remote |
|
283 |
ret->remote_x = (int16_t)gunner_get_x (remote); |
|
284 |
ret->remote_y = (int16_t)gunner_get_y (remote); |
|
285 |
ret->remote_angle = (int16_t)gunner_get_angle (remote); |
|
286 |
ret->remote_health = (int16_t)gunner_get_health (remote); |
|
287 |
ret->remote_current_health = (int16_t)gunner_get_curr_health(remote); |
|
278 | 288 |
|
279 |
while(true){ |
|
280 |
x = rand() % w; |
|
281 |
y = rand() % h; |
|
282 |
gunner_set_pos(p, x, y); |
|
283 |
if(map_collides_gunner(map, p)) continue; |
|
284 |
int collides = false; |
|
285 |
list_node_t *it = list_begin(l); |
|
286 |
while(it != list_end(l)){ |
|
287 |
if(gunner_collides_gunner(p, *list_node_val(it))){ |
|
288 |
collides = true; |
|
289 |
break; |
|
290 |
} |
|
291 |
it = list_node_next(it); |
|
292 |
} |
|
293 |
if(!collides) return; |
|
294 |
} |
|
289 |
//ret->no_bullets = 0; |
|
290 |
|
|
291 |
return ret; |
|
295 | 292 |
} |
293 |
void host_info_dtor(host_info_t *p) { |
|
294 |
if (p==NULL) return; |
|
295 |
/* |
|
296 |
if ((p->bullets_x) != NULL){ free(p->bullets_x); p->bullets_x = NULL; } |
|
296 | 297 |
|
297 |
static int16_t mouse_x = 0, mouse_y = 0;
|
|
298 |
if ((p->bullets_y) != NULL){ free(p->bullets_y); p->bullets_y = NULL; }
|
|
298 | 299 |
|
299 |
void (update_mouse)(struct packet *p) { |
|
300 |
mouse_x = max_16(0, mouse_x + p->delta_x); |
|
301 |
mouse_x = min_16(mouse_x, (int16_t)graph_get_XRes() - 1); |
|
300 |
if ((p->bullets_vx) != NULL){ free(p->bullets_vx); p->bullets_vx = NULL; } |
|
302 | 301 |
|
303 |
mouse_y = max_16(0, mouse_y - p->delta_y); |
|
304 |
mouse_y = min_16(mouse_y, (int16_t)graph_get_YRes() - 1); |
|
302 |
if ((p->bullets_vy) != NULL){ free(p->bullets_vy); p->bullets_vy = NULL; } |
|
305 | 303 |
|
306 |
key_presses.lb_pressed = p->lb; |
|
304 |
if ((p->bullets_shooter) != NULL){ free(p->bullets_shooter); p->bullets_shooter = NULL; } |
|
305 |
*/ |
|
306 |
free(p); |
|
307 | 307 |
} |
308 | 308 |
|
309 |
keys_t* (get_key_presses)(void) { |
|
310 |
return &key_presses; |
|
309 |
remote_info_t* remote_info_ctor(void) { |
|
310 |
remote_info_t *ret = (remote_info_t*)malloc(sizeof(remote_info_t)); |
|
311 |
if (ret == NULL) return ret; |
|
312 |
|
|
313 |
memset(&(ret->remote_keys_pressed), 0, sizeof(keys_t)); |
|
314 |
|
|
315 |
ret->remote_angle = 0; |
|
316 |
|
|
317 |
return ret; |
|
311 | 318 |
} |
319 |
void remote_info_dtor(remote_info_t *p) { |
|
320 |
if (p==NULL) return; |
|
321 |
free(p); |
|
322 |
} |
|
312 | 323 |
|
313 |
int16_t* get_mouse_X(void) { return &mouse_x; } |
|
324 |
bullet_info_t* bullet_info_ctor(void) { |
|
325 |
bullet_info_t *ret = (bullet_info_t*)malloc(sizeof(bullet_info_t)); |
|
326 |
if (ret == NULL) return ret; |
|
314 | 327 |
|
315 |
int16_t* get_mouse_Y(void) { return &mouse_y; }
|
|
328 |
ret->new_bullet = false;
|
|
316 | 329 |
|
317 |
double get_mouse_angle(gunner_t *p) { |
|
318 |
return atan2(gunner_get_y_screen(p) - mouse_y, mouse_x - gunner_get_x_screen(p)); |
|
330 |
return ret; |
|
319 | 331 |
} |
332 |
void bullet_info_dtor(bullet_info_t *p) { |
|
333 |
if (p == NULL) return; |
|
334 |
free(p); |
|
335 |
} |
|
320 | 336 |
|
321 | 337 |
void build_host_structure(host_info_t *p, gunner_t *host, gunner_t *remote) { |
322 | 338 |
// host |
... | ... | |
356 | 372 |
} |
357 | 373 |
*/ |
358 | 374 |
} |
359 |
|
|
360 | 375 |
void build_remote_structure(remote_info_t *p, keys_t *keys, double angle) { |
361 | 376 |
memcpy(&(p->remote_keys_pressed), keys, sizeof(keys_t)); |
362 | 377 |
p->remote_angle = angle; |
363 | 378 |
} |
364 |
|
|
365 |
text_timer_t* (timer_ctor)(const font_t *fnt){ |
|
366 |
if(fnt == NULL) return NULL; |
|
367 |
text_timer_t *ret = malloc(sizeof(timer_t)); |
|
368 |
if (ret == NULL) return NULL; |
|
369 |
ret->time = 0; |
|
370 |
ret->text = text_ctor(fnt, "000s"); |
|
371 |
text_set_color(ret->text, TEXT_COLOR); |
|
372 |
return ret; |
|
373 |
} |
|
374 |
|
|
375 |
void (timer_update)(text_timer_t *p){ |
|
376 |
if (p->time >= 999) return; |
|
377 |
p->time++; |
|
378 |
char buffer[100]; |
|
379 |
sprintf(buffer, "%03ds", p->time); |
|
380 |
text_set_string(p->text, buffer); |
|
381 |
} |
|
382 |
|
|
383 |
void (timer_reset)(text_timer_t *p){ |
|
384 |
text_set_string(p->text, "000s"); |
|
385 |
} |
|
386 |
|
|
387 |
void (timer_dtor)(text_timer_t *p){ |
|
388 |
if (p == NULL) return; |
|
389 |
text_dtor(p->text); |
|
390 |
free(p); |
|
391 |
} |
Also available in: Unified diff