Revision 233
gunner collision with other dudes
proj/include/ent.h | ||
---|---|---|
56 | 56 |
int (map_collides_gunner)(const map_t *p, const gunner_t *gunner); |
57 | 57 |
int (map_collides_bullet)(const map_t *p, const bullet_t *bullet); |
58 | 58 |
int (gunner_collides_bullet)(const gunner_t *shooter, const bullet_t *bull); |
59 |
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2); |
|
59 | 60 |
void (map_draw)(map_t *p); |
60 | 61 |
|
61 | 62 |
#endif //ENT_H_INCLUDED |
proj/include/proj_func.h | ||
---|---|---|
17 | 17 |
/** |
18 | 18 |
* @brief Updates movement variables. |
19 | 19 |
*/ |
20 |
void update_movement(const map_t *map, gunner_t *p); |
|
20 |
void update_movement(const map_t *map, gunner_t *p, gunner_t *p2);
|
|
21 | 21 |
|
22 | 22 |
typedef struct keys { |
23 | 23 |
uint8_t w_pressed : 1; |
proj/src/ent.c | ||
---|---|---|
260 | 260 |
return distance <= shooter_radius+bullet_radius; |
261 | 261 |
} |
262 | 262 |
|
263 |
int (gunner_collides_gunner)(const gunner_t *shooter1, const gunner_t *shooter2) { |
|
264 |
double shooter1_radius = max(sprite_get_w(shooter1->dude), sprite_get_h(shooter1->dude))/2.0; |
|
265 |
double shooter1_x = gunner_get_x(shooter1); |
|
266 |
double shooter1_y = gunner_get_y(shooter1); |
|
267 |
|
|
268 |
double shooter2_radius = max(sprite_get_w(shooter2->dude), sprite_get_h(shooter2->dude))/2.0; |
|
269 |
double shooter2_x = gunner_get_x(shooter2); |
|
270 |
double shooter2_y = gunner_get_y(shooter2); |
|
271 |
|
|
272 |
double dx = shooter1_x - shooter2_x; |
|
273 |
double dy = shooter1_y - shooter2_y; |
|
274 |
double distance = sqrt(dx*dx + dy*dy); |
|
275 |
return distance <= shooter1_radius+shooter2_radius; |
|
276 |
} |
|
277 |
|
|
263 | 278 |
void (map_draw)(map_t *p){ |
264 | 279 |
const int16_t x_screen = map_get_x_screen(p); |
265 | 280 |
const int16_t y_screen = map_get_y_screen(p); |
proj/src/proj.c | ||
---|---|---|
184 | 184 |
#ifdef TELMO |
185 | 185 |
if (i == 0) { |
186 | 186 |
if (no_interrupts % refresh_count_value == 0) { |
187 |
update_movement(map1, shooter1); |
|
187 |
update_movement(map1, shooter1, shooter2);
|
|
188 | 188 |
//bullet_update_movement(bullet); |
189 | 189 |
|
190 | 190 |
if (no_interrupts % 180 == 0) gunner_set_pos(shooter2, 775, 75); |
proj/src/proj_func.c | ||
---|---|---|
52 | 52 |
hor_mov = key_presses.d_pressed - key_presses.a_pressed; |
53 | 53 |
} |
54 | 54 |
|
55 |
void update_movement(const map_t *map, gunner_t *p) { |
|
55 |
void update_movement(const map_t *map, gunner_t *p, gunner_t *p2) {
|
|
56 | 56 |
double x = gunner_get_x(p); |
57 | 57 |
double y = gunner_get_y(p); |
58 | 58 |
gunner_set_pos(p, x + SHOOTER_SPEED * hor_mov, y); |
59 |
if (map_collides_gunner(map, p)) { |
|
59 |
if (map_collides_gunner(map, p) || gunner_collides_gunner(p, p2)) {
|
|
60 | 60 |
gunner_set_pos(p, x, y); |
61 | 61 |
} |
62 | 62 |
x = gunner_get_x(p); |
63 | 63 |
gunner_set_pos(p, x, y + SHOOTER_SPEED * ver_mov); |
64 |
if (map_collides_gunner(map, p)) { |
|
64 |
if (map_collides_gunner(map, p) || gunner_collides_gunner(p, p2)) {
|
|
65 | 65 |
gunner_set_pos(p, x, y); |
66 | 66 |
} |
67 | 67 |
} |
Also available in: Unified diff