diff options
Diffstat (limited to 'src')
-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); } |