diff options
author | P. J. McDermott <pj@pehjota.net> | 2021-03-30 03:42:37 (EDT) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2021-03-30 03:42:37 (EDT) |
commit | 75cbbd416551fdcc789ffd215e1121c8d129e732 (patch) | |
tree | 06e2dba15cc9678160f4b92c1214cd967ebce9f8 | |
parent | 6069e79e7f2b7a0c2479096bec4cf839811fac8e (diff) | |
download | dodge-balls-75cbbd416551fdcc789ffd215e1121c8d129e732.zip dodge-balls-75cbbd416551fdcc789ffd215e1121c8d129e732.tar.gz dodge-balls-75cbbd416551fdcc789ffd215e1121c8d129e732.tar.bz2 |
ball: Avoid double bouncing off points
-rw-r--r-- | src/ball.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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; } } } |