diff options
Diffstat (limited to 'Week1-Pacman/src/collision.c')
-rw-r--r-- | Week1-Pacman/src/collision.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Week1-Pacman/src/collision.c b/Week1-Pacman/src/collision.c new file mode 100644 index 0000000..268be95 --- /dev/null +++ b/Week1-Pacman/src/collision.c @@ -0,0 +1,15 @@ +#include "collision.h" + +bool is_colliding(SDL_Rect* a, SDL_Rect* b) { + bool collision_v, collision_h; + + collision_h = + (a->x <= b->x && a->x + a->w - 1 >= b->x) || + (b->x <= a->x && b->x + b->w - 1 >= a->x); + + collision_v = + (a->y <= b->y && a->y + a->h - 1 >= b->y) || + (b->y <= a->y && b->y + b->h - 1 >= a->y); + + return collision_v && collision_h; +} |