From 98b9f36db18a5702a1c85421e8b0f71e73d1177e Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Tue, 30 Mar 2021 04:23:20 -0400 Subject: ball: Collide with balls before lines 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. --- diff --git a/src/ball.c b/src/ball.c index 4dc0ab0..923994e 100644 --- a/src/ball.c +++ b/src/ball.c @@ -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); } -- cgit v0.9.1