summaryrefslogtreecommitdiff
path: root/Week1-Pacman/src/collision.c
blob: 268be9562b59c64587eda39062d4e341dbb6d885 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;
}