game_math.c 251 B

12345678910111213
  1. #include "game_math.h"
  2. int game_math_collide(SDL_Rect *r1, SDL_Rect *r2) {
  3. return (
  4. // collision on X
  5. (r1->x < (r2->x +r2->w)) !=
  6. ((r1->x +r1->w) <= r2->x) &&
  7. // collision on Y
  8. (r1->y < (r2->y +r2->h)) !=
  9. ((r1->y +r1->h) <= r2->y)
  10. );
  11. }