summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorP. 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)
commit98b9f36db18a5702a1c85421e8b0f71e73d1177e (patch)
treeaf16e26af0f11689c3f10659b48af70eff7619fb
parent486a72a549d928b3ac2ba806ca6ce8bb17b14a09 (diff)
downloaddodge-balls-98b9f36db18a5702a1c85421e8b0f71e73d1177e.zip
dodge-balls-98b9f36db18a5702a1c85421e8b0f71e73d1177e.tar.gz
dodge-balls-98b9f36db18a5702a1c85421e8b0f71e73d1177e.tar.bz2
ball: Collide with balls before linesHEADmaster
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.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);
}