-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControllerObject.cpp
More file actions
63 lines (52 loc) · 1.52 KB
/
ControllerObject.cpp
File metadata and controls
63 lines (52 loc) · 1.52 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
#include "ControllerObject.h"
#include "SpriteObject.h"
#include "Globals.h"
ControllerObject::ControllerObject(SpriteObject* targetSprite):
controlledSprite(NULL), xSpeed(0), ySpeed(0), enabled(true), flippedControls(false)
{
if (targetSprite)
controlledSprite = targetSprite;
}
SpriteObject* const ControllerObject::GetControlledSprite()
{
return controlledSprite;
}
int const ControllerObject::GetXPos()
{
if (controlledSprite)
return controlledSprite -> GetXPos();
return 0;
}
int const ControllerObject::GetYPos()
{
if (controlledSprite)
return controlledSprite -> GetYPos();
return 0;
}
bool const ControllerObject::IsEnabled()
{ return enabled; }
void ControllerObject::Enable()
{ enabled = true; }
void ControllerObject::Disable()
{ enabled = false; }
void ControllerObject::SetPosition(int x, int y)
{
if (controlledSprite)
controlledSprite -> ChangePos(x,y);
}
float const ControllerObject::GetXSpeed()
{ return xSpeed; }
float const ControllerObject::GetYSpeed()
{ return ySpeed; }
void ControllerObject::Move(float scale)
{
if (controlledSprite)
{
float timestep = 1.0 / GameGlobals::GetFPS();
int pixelsPerUnit = GameGlobals::GetUnitPixels();
//Timestep * xSpeed * pixelsPerUnit * scale = new position X (same for Y)
//Euler integration to change position. Hitboxes handled elsewhere.
controlledSprite -> ChangePos(timestep * xSpeed * pixelsPerUnit * scale + controlledSprite -> GetXPos(),
timestep * ySpeed * pixelsPerUnit * scale + controlledSprite -> GetYPos());
}
}