Archimedes/Dash Da Capo!
Loading...
Searching...
No Matches
isColliding.h
1#pragma once
2
3bool isColliding(const SDL_Rect* rect1, const SDL_Rect* rect2)
4{
5 int leftRect1, leftRect2,
6 topRect1, topRect2,
7 rightRect1, rightRect2,
8 bottomRect1, bottomRect2;
9
10 leftRect1 = rect1->x;
11 leftRect2 = rect2->x;
12 topRect1 = rect1->y;
13 topRect2 = rect2->y;
14 rightRect1 = rect1->x + rect1->w;
15 rightRect2 = rect2->x + rect2->w;
16 bottomRect1 = rect1->y + rect1->h;
17 bottomRect2 = rect2->y + rect2->h;
18
19 if (leftRect1 >= rightRect2 ||
20 leftRect2 >= rightRect1 ||
21 topRect1 >= bottomRect2 ||
22 topRect2 >= bottomRect1)
23 {
24 return false;
25 }
26
27 return true;
28}