forked from annoyatron255/Game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneral.cpp
45 lines (36 loc) · 1.03 KB
/
General.cpp
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
#include "General.h"
General::General() {
}
void General::checkCollision(Input *input, SDL_Rect &s1Rect, SDL_Rect &e1Rect, int screenw, int screenh) {
if (touching(s1Rect, e1Rect)) {
input->setGameDone();
}
if (s1Rect.y < 0) {
s1Rect.y = 0;
}
if ((s1Rect.y + s1Rect.h) > screenh) {
s1Rect.y = screenh - s1Rect.h;
}
if (s1Rect.x < 0) {
s1Rect.x = 0;
}
if ((s1Rect.x + s1Rect.w) > screenw) {
s1Rect.x = screenw - s1Rect.w;
}
}
/*
int General::overlap(SDL_Rect rect1, SDL_Rect rect2) {
if ((((abs(((rect2.x+(rect2.w/2))-(rect1.x+(rect1.w/2)))))<((rect1.w+rect2.w)/2))&((abs(((rect2.y+(rect2.h/2))-(rect1.y+(rect1.h/2)))))<((rect1.h+rect2.h)/2))) == 1) {
return true;
} else {
return false;
}
}
*/
int General::touching(SDL_Rect &rect1, SDL_Rect &rect2) {
if ( (((abs(((rect2.x+(rect2.w/2))-(rect1.x+(rect1.w/2)))))<=((rect1.w+rect2.w)/2))&((abs(((rect2.y+(rect2.h/2))-(rect1.y+(rect1.h/2)))))<=((rect1.h+rect2.h)/2))) == 1) {
return true;
} else {
return false;
}
}