Revision 341
more changes in ent.h, ent.c
proj/include/ent.h | ||
---|---|---|
414 | 414 |
*/ |
415 | 415 |
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull); |
416 | 416 |
|
417 |
void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l); |
|
418 |
|
|
419 | 417 |
#endif //ENT_H_INCLUDED |
proj/include/proj_func.h | ||
---|---|---|
28 | 28 |
*/ |
29 | 29 |
void update_movement(map_t *map, gunner_t *p, keys_t *keys, list_t *shooter_list); |
30 | 30 |
|
31 |
/** |
|
32 |
* @brief Get random spawn (actually, position) for new gunner. |
|
33 |
* |
|
34 |
* The new position cannot collide with the map, nor with any of the gunners |
|
35 |
* already in the list. |
|
36 |
* @param map Pointer to map |
|
37 |
* @param p Pointer to new gunner |
|
38 |
* @param l List of gunners that already exist |
|
39 |
*/ |
|
40 |
void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l); |
|
41 |
|
|
31 | 42 |
void update_mouse(struct packet *p); |
32 | 43 |
|
33 | 44 |
keys_t* (get_key_presses)(void); |
proj/src/ent.c | ||
---|---|---|
381 | 381 |
double distance = sqrt(dx*dx + dy*dy); |
382 | 382 |
return distance <= shooter_radius+bullet_radius; |
383 | 383 |
} |
384 |
void (get_random_spawn)(const map_t *map, gunner_t *p, list_t *l) { |
|
385 |
uint16_t w = map_get_width(map), h = map_get_height(map); |
|
386 |
double x, y; |
|
387 |
|
|
388 |
while(true){ |
|
389 |
x = rand() % w; |
|
390 |
y = rand() % h; |
|
391 |
gunner_set_pos(p, x, y); |
|
392 |
if(map_collides_gunner(map, p)) continue; |
|
393 |
int collides = false; |
|
394 |
list_node_t *it = list_begin(l); |
|
395 |
while(it != list_end(l)){ |
|
396 |
if(gunner_collides_gunner(p, *list_node_val(it))){ |
|
397 |
collides = true; |
|
398 |
break; |
|
399 |
} |
|
400 |
it = list_node_next(it); |
|
401 |
} |
|
402 |
if(!collides) return; |
|
403 |
} |
|
404 |
} |
proj/src/proj_func.c | ||
---|---|---|
272 | 272 |
last_minus = key_presses.minus_pressed; |
273 | 273 |
} |
274 | 274 |
|
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; |
|
278 |
|
|
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 |
} |
|
295 |
} |
|
296 |
|
|
275 | 297 |
static int16_t mouse_x = 0, mouse_y = 0; |
276 | 298 |
|
277 | 299 |
void (update_mouse)(struct packet *p) { |
Also available in: Unified diff