-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.cpp
52 lines (39 loc) · 1.49 KB
/
helpers.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
46
47
48
49
50
51
52
#include "helpers.h"
namespace SSJ {
Point Helpers::getOnScreenPosition(Point position){
return Helpers::getOnScreenPosition(position.x, position.y);
}
bool Helpers::isInScreen(Point position){
return Helpers::isInScreen(position.x, position.y);
}
Point Helpers::getOnScreenPosition(float x, float y){
Point objectPosition;
objectPosition.x = x - DataContainer::ScreenPosition.x;
objectPosition.y = y - DataContainer::ScreenPosition.y;
return objectPosition;
}
bool Helpers::isInScreen(float x, float y){
Point virtualScreen;
virtualScreen.x = DataContainer::ScreenPosition.x - DataContainer::ScreenMargin;
virtualScreen.y = DataContainer::ScreenPosition.y - DataContainer::ScreenMargin;
size_t virtualScreenWidth = DataContainer::ScreenWidth + 2 * DataContainer::ScreenMargin;
size_t virtualScreenHeight = DataContainer::ScreenHeight + 2 * DataContainer::ScreenMargin;
if(x <= virtualScreen.x && x >= virtualScreen.x+virtualScreenWidth)
return false;
if(y <= virtualScreen.y && y >= virtualScreen.y+virtualScreenHeight)
return false;
return true;
}
bool Helpers::checkCollision(sf::Rect<float> a, sf::Rect<float> b)
{
if(a.left + a.width < b.left)
return false;
if(a.top + a.height < b.top )
return false;
if(a.left > b.left + b.width)
return false;
if(a.top > b.top + b.height)
return false;
return true;
}
}