-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollision.cpp
More file actions
51 lines (36 loc) · 1023 Bytes
/
collision.cpp
File metadata and controls
51 lines (36 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "collision.h"
bool collision(SDL_Surface* surfacea, int ax, int ay, int asize, SDL_Surface* surfaceb, int bx, int by, int bsize)
{
// if the righmost point of surface a is further left than the leftmost point of surfaceb, or the rightmost point of surface b is further left than the leftmost point of surface a, there is no collision.
int aRight = ax+asize;
int bRight = bx+bsize;
if ((ax > bRight) || (bx > aRight))
{
return false;
}
// if the highest point of surfacea is lower than the lowest point of surfaceb, or the highest point of surfaceb is lower than the lowest point of surfacea, there is no collision.
int aBottom = ay+asize;
int bBottom = by+bsize;
if ((ay > bBottom) || (by > aBottom))
{
return false;
}
// if none of those is true, then there is a collision, and our function returns true
return true;
}
int bound_max(int a, int b)
{
if (a > b)
{
return a;
}
return b;
}
int bound_min(int a, int b)
{
if (a < b)
{
return a;
}
return b;
}