diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-03-30 04:23:20 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-03-30 04:23:20 (EDT) |
commit | 98b9f36db18a5702a1c85421e8b0f71e73d1177e (patch) | |
tree | af16e26af0f11689c3f10659b48af70eff7619fb | |
parent | 486a72a549d928b3ac2ba806ca6ce8bb17b14a09 (diff) | |
download | dodge-balls-98b9f36db18a5702a1c85421e8b0f71e73d1177e.zip dodge-balls-98b9f36db18a5702a1c85421e8b0f71e73d1177e.tar.gz dodge-balls-98b9f36db18a5702a1c85421e8b0f71e73d1177e.tar.bz2 |
Seems to fix an issue of a ball getting stuck on a line when colliding
with both a line and a ball in the same frame.
-rw-r--r-- | src/ball.c | 32 |
1 files changed, 16 insertions, 16 deletions
@@ -111,6 +111,9 @@ _db_ball_bounce(struct db_ball *ball, double col_x, double col_y) void db_balls_collisions(struct db_ball *ball) { + struct db_ball *other; + double col_x; + double col_y; struct db_map_line *line; double prev_col_x; double prev_col_y; @@ -118,9 +121,19 @@ db_balls_collisions(struct db_ball *ball) int line_y1; int line_x2; int line_y2; - double col_x; - double col_y; - struct db_ball *other; + + /* Spinning balls shouldn't collide with any other balls */ + if (ball->sr == 0) { + for (other = ball->next; other != NULL; other = other->next) { + if (other->sr == 0 && db_col_pt_cir_cir( + ball->x, ball->y, ball->r, + other->x, other->y, other->r, + &col_x, &col_y)) { + _db_ball_bounce(ball , col_x, col_y); + _db_ball_bounce(other, col_x, col_y); + } + } + } /* Spinning balls shouldn't bounce off walls */ if (ball->sr == 0) { @@ -144,19 +157,6 @@ db_balls_collisions(struct db_ball *ball) } } - /* Spinning balls shouldn't collide with any other balls */ - if (ball->sr == 0) { - for (other = ball->next; other != NULL; other = other->next) { - if (other->sr == 0 && db_col_pt_cir_cir( - ball->x, ball->y, ball->r, - other->x, other->y, other->r, - &col_x, &col_y)) { - _db_ball_bounce(ball , col_x, col_y); - _db_ball_bounce(other, col_x, col_y); - } - } - } - if (ball->next != NULL) { db_balls_collisions(ball->next); } |