summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/ball.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/ball.c b/src/ball.c
index 14ee8de..d4c27a4 100644
--- a/src/ball.c
+++ b/src/ball.c
@@ -118,11 +118,13 @@ 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];
int x;
int y;
- struct db_ball *other;
double col_x;
double col_y;
+ struct db_ball *other;
wall.w = map_tw = db_map_get_tilewidth (ball->map);
wall.h = map_th = db_map_get_tileheight(ball->map);
@@ -130,6 +132,10 @@ 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;
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)) {
@@ -137,7 +143,26 @@ 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;
+ }
}
}
}