-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtilities.cpp
41 lines (33 loc) · 1.25 KB
/
Utilities.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
#include "Utilities.h"
//Constructors / Destructors
Utilities::Utilities()
{
}
Utilities::~Utilities()
{
}
//Functions
sf::Vector2f Utilities::adjustToCamera(Global* global, sf::Vector2f entityPos)
{
return entityPos - global->getCameraOfst();
}
void Utilities::cameraStickToX(Global *global, float entityPosX, float offset)
{
global->setCameraOfst(sf::Vector2f(entityPosX+offset, global->getCameraOfst().y));
}
void Utilities::cameraStickToY(Global *global, float entityPosY, float offset)
{
global->setCameraOfst(sf::Vector2f(global->getCameraOfst().x, entityPosY+offset));
}
sf::Vector2f Utilities::boundaryCollision(Global *global, sf::Vector2f entityPos, sf::Vector2f entityVel)
{
if (entityPos.x > global->getBoundaries().width/2.f + global->getScreenSize().width/2.f)
entityVel.x = -fabs(entityVel.x);
if (entityPos.x < -(global->getBoundaries().width/2.f) + global->getScreenSize().width/2.f)
entityVel.x = fabs(entityVel.x);
if (entityPos.y > global->getBoundaries().height/2.f + global->getScreenSize().height/2.f)
entityVel.y = -fabs(entityVel.y);
if (entityPos.y < -(global->getBoundaries().height/2.f) + global->getScreenSize().height/2.f)
entityVel.y = fabs(entityVel.y);
return entityVel;
}