diff options
-rw-r--r-- | src/ball.c | 40 |
1 files changed, 18 insertions, 22 deletions
@@ -60,43 +60,39 @@ db_ball_new(int x, int y, int r, int a, int d, int sr, double s, return ball; } -static void -_db_ball_collisions(struct db_ball *this) +void +db_balls_collisions(struct db_ball *ball) { - struct db_ball *that; + struct db_ball *other; int col_x; int col_y; - for (that = this->next; that != NULL; that = that->next) { - if (db_col_pt_cir_cir(this->x, this->y, this->r, - that->x, that->y, that->r, + for (; other != NULL; other = other->next) { + if (db_col_pt_cir_cir(ball->x, ball->y, ball->r, + other->x, other->y, other->r, &col_x, &col_y)) { /* TODO: Reverse direction */ } } -} -void -db_balls_collisions(struct db_ball *ball_head) -{ - struct db_ball *ball; - - for (ball = ball_head; ball != NULL; ball = ball->next) { - _db_ball_collisions(ball); + if (ball->next != NULL) { + db_balls_collisions(ball->next); } } int -db_balls_player_collisions(struct db_ball *ball_head, +db_balls_player_collisions(struct db_ball *ball, int player_x, int player_y, int player_r) { - struct db_ball *ball; + if (db_col_cir_cir(ball->x, ball->y, ball->r, + player_x, player_y, player_r)) { + return 1; + } - for (ball = ball_head; ball != NULL; ball = ball->next) { - if (db_col_cir_cir(ball->x, ball->y, ball->r, - player_x, player_y, player_r)) { - return 1; - } + if (ball->next != NULL) { + return db_balls_player_collisions(ball->next, + player_x, player_y, player_r); + } else { + return 0; } - return 0; } |