diff options
Diffstat (limited to 'src/collision.c')
-rw-r--r-- | src/collision.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/collision.c b/src/collision.c index 32c5e57..2abd8a2 100644 --- a/src/collision.c +++ b/src/collision.c @@ -18,6 +18,7 @@ */ #include <SDL.h> +#include "collision.h" int db_pt_in_rect(int x, int y, SDL_Rect *rect) @@ -36,3 +37,28 @@ db_pt_in_rect(int x, int y, SDL_Rect *rect) } return 1; } + +int +db_col_cir_cir(int x1, int y1, int r1, int x2, int y2, int r2) +{ + return ((r1 + r2) * (r1 + r2)) >= + ((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); +} + +/* + * This function will be called after moving the two balls being checked. A + * more accurate way to handle collisions would be to microstep through + * movements to find the exact point of collision. + */ +int +db_col_pt_cir_cir(int x1, int y1, int r1, int x2, int y2, int r2, + int *col_x, int *col_y) +{ + if (db_col_cir_cir(x1, y1, r1, x2, y2, r2)) { + *col_x = (x1 + x2) / 2; + *col_y = (y1 + y2) / 2; + return 1; + } else { + return 0; + } +} |