From 6f3fe42d5888e70fe195b6bbf32b7bdd4059415b Mon Sep 17 00:00:00 2001 From: BoredGuy Date: Wed, 25 Dec 2024 16:10:31 +0300 Subject: Started work on collisions --- Week1-Pacman/src/collision.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Week1-Pacman/src/collision.c (limited to 'Week1-Pacman/src/collision.c') 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; +} -- cgit v1.2.3