From 75cbbd416551fdcc789ffd215e1121c8d129e732 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Tue, 30 Mar 2021 03:42:37 -0400 Subject: ball: Avoid double bouncing off points --- diff --git a/src/ball.c b/src/ball.c index 99415cc..2666a6e 100644 --- a/src/ball.c +++ b/src/ball.c @@ -112,6 +112,8 @@ void db_balls_collisions(struct db_ball *ball) { struct db_map_line *line; + double prev_col_x; + double prev_col_y; int line_x1; int line_y1; int line_x2; @@ -122,6 +124,7 @@ db_balls_collisions(struct db_ball *ball) /* Spinning balls shouldn't bounce off walls */ if (ball->sr == 0) { + prev_col_x = prev_col_y = -1; for (line = db_map_get_lines(ball->map); line != NULL; line = db_map_line_get_next(line)) { db_map_line_get_coords(line, &line_x1, &line_y1, @@ -131,8 +134,12 @@ db_balls_collisions(struct db_ball *ball) line_x1, line_y1, line_x2, line_y2, &col_x, &col_y)){ + if (col_x == prev_col_x || col_y == prev_col_y){ + continue; + } _db_ball_bounce(ball, col_x, col_y); - break; + prev_col_x = col_x; + prev_col_y = col_y; } } } -- cgit v0.9.1