summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ball.c32
1 files changed, 16 insertions, 16 deletions
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);
}