summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ball.c32
1 files changed, 6 insertions, 26 deletions
diff --git a/src/ball.c b/src/ball.c
index d4c27a4..552aadd 100644
--- a/src/ball.c
+++ b/src/ball.c
@@ -118,8 +118,7 @@ db_balls_collisions(struct db_ball *ball)
int x_max;
int y_min;
int y_max;
- int prev_col_x[2];
- int prev_col_y[2];
+ SDL_bool bounce;
int x;
int y;
double col_x;
@@ -132,10 +131,7 @@ db_balls_collisions(struct db_ball *ball)
x_max = ceil ((ball->x + ball->r) / map_tw);
y_min = floor((ball->y - ball->r) / map_th);
y_max = ceil ((ball->y + ball->r) / map_th);
- prev_col_x[0] = -1;
- prev_col_x[1] = -1;
- prev_col_y[0] = -1;
- prev_col_y[1] = -1;
+ bounce = SDL_FALSE;
for (y = y_min; y < y_max; ++y) {
for (x = x_min; x < x_max; ++x) {
if (db_map_tile_ball_collides(ball->map, x, y)) {
@@ -143,30 +139,14 @@ db_balls_collisions(struct db_ball *ball)
wall.y = y * map_th;
if (db_col_cir_rect(ball->x, ball->y, ball->r,
&wall, &col_x, &col_y)){
- if (x == prev_col_x[0]) {
- continue;
- } else if (x == prev_col_x[1]) {
- continue;
- } else if (y == prev_col_y[0]) {
- continue;
- } else if (y == prev_col_y[1]) {
- continue;
- }
- _db_ball_bounce(ball, col_x, col_y);
- if (prev_col_x[0] >= 0) {
- prev_col_x[0] = x;
- } else {
- prev_col_x[1] = x;
- }
- if (prev_col_y[0] >= 0) {
- prev_col_y[0] = y;
- } else {
- prev_col_y[1] = y;
- }
+ bounce = SDL_TRUE;
}
}
}
}
+ if (bounce) {
+ _db_ball_bounce(ball, col_x, col_y);
+ }
/* Spinning balls shouldn't collide with any other balls */
if (ball->sr == 0) {