diff options
-rw-r--r-- | src/ball.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -95,6 +95,15 @@ db_balls_move(struct db_ball *ball) } } +static void +_db_ball_bounce(struct db_ball *ball, double col_x, double col_y) +{ + double col_a; + + col_a = atan2(col_y - ball->y, col_x - ball->x) * 180 / M_PI; + ball->a = (2 * col_a - ball->a - 180) % 360; +} + void db_balls_collisions(struct db_ball *ball) { @@ -109,7 +118,8 @@ db_balls_collisions(struct db_ball *ball) ball->x, ball->y, ball->r, other->x, other->y, other->r, &col_x, &col_y)) { - /* TODO: Reverse direction */ + _db_ball_bounce(ball , col_x, col_y); + _db_ball_bounce(other, col_x, col_y); } } } |