-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneralFunc.cpp
More file actions
97 lines (84 loc) · 1.92 KB
/
Copy pathGeneralFunc.cpp
File metadata and controls
97 lines (84 loc) · 1.92 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "GeneralFunc.h"
bool SDLGeneralFunc::CheckCollision(const SDL_Rect& object1, const SDL_Rect& object2)
{
int left_a = object1.x;
int right_a = object1.x + object1.w;
int top_a = object1.y;
int bottom_a = object1.y + object1.h;
int left_b = object2.x;
int right_b = object2.x + object2.w;
int top_b = object2.y;
int bottom_b = object2.y + object2.h;
// Case 1: size object 1 < size object 2
if (left_a > left_b && left_a < right_b)
{
if (top_a > top_b && top_a < bottom_b)
{
return true;
}
}
if (left_a > left_b && left_a < right_b)
{
if (bottom_a > top_b && bottom_a < bottom_b)
{
return true;
}
}
if (right_a > left_b && right_a < right_b)
{
if (top_a > top_b && top_a < bottom_b)
{
return true;
}
}
if (right_a > left_b && right_a < right_b)
{
if (bottom_a > top_b && bottom_a < bottom_b)
{
return true;
}
}
// Case 2: size object 1 < size object 2
if (left_b > left_a && left_b < right_a)
{
if (top_b > top_a && top_b < bottom_a)
{
return true;
}
}
if (left_b > left_a && left_b < right_a)
{
if (bottom_b > top_a && bottom_b < bottom_a)
{
return true;
}
}
if (right_b > left_a && right_b < right_a)
{
if (top_b > top_a && top_b < bottom_a)
{
return true;
}
}
if (right_b > left_a && right_b < right_a)
{
if (bottom_b > top_a && bottom_b < bottom_a)
{
return true;
}
}
// Case 3: size object 1 = size object 2
if (top_a == top_b && right_a == right_b && bottom_a == bottom_b)
{
return true;
}
return false;
}
bool SDLGeneralFunc::isInside(int& x, int& y, SDL_Rect object)
{
if(x >= object.x && x <= object.x+object.w && y >= object.y && y <= object.y + object.h)
{
return true;
}
return false;
}