diff options
author | BoredGuy <osome3717@gmail.com> | 2024-12-25 16:10:31 +0300 |
---|---|---|
committer | BoredGuy <osome3717@gmail.com> | 2024-12-25 16:10:31 +0300 |
commit | 6f3fe42d5888e70fe195b6bbf32b7bdd4059415b (patch) | |
tree | 024b054c282167c5d093cf3671368bb71d238002 /Week1-Pacman/src/collision.c | |
parent | 7340dcda9151c50c84e283f102ea2f44dbf1443f (diff) |
Started work on collisions
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; +} |