-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveProcess.cpp
More file actions
83 lines (69 loc) · 2.11 KB
/
MoveProcess.cpp
File metadata and controls
83 lines (69 loc) · 2.11 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
#include "MoveProcess.h"
#include "Services.h"
#include "PhysicsComponent.h"
// Default constructor
MoveProcess::MoveProcess(int targetObjectID, float targetDistance, float vx, float vy) :
targetObjectID(targetObjectID),
targetDistance(targetDistance),
vx(vx),
vy(vy)
{
distanceElapsed = 0.0f;
// Register targetObjectID as an object being used.
Services::componentManager()->gameObjRegisterDependency(targetObjectID);
}
// error - remember delegating constructor cannot have another mem-initializer
// including superclass constructors, apparently.
MoveProcess::MoveProcess(int callbkCoroutine, int targetObjectID,
float targetDistance, float vx, float vy) :
LuaCallbackProcess(callbkCoroutine),
targetObjectID(targetObjectID),
targetDistance(targetDistance),
vx(vx),
vy(vy)
{
distanceElapsed = 0.0f;
// Register targetObjectID as an object being used.
Services::componentManager()->gameObjRegisterDependency(targetObjectID);
}
// Default destructor
MoveProcess::~MoveProcess()
{
cout << "Destroyed MoveProcess for " << targetObjectID << endl;
// Unregister targetObjectID
}
void MoveProcess::update(float dt)
{
//cout << " Distance elapsed: " << distanceElapsed << ". Target distance: " << targetDistance << endl;
if (distanceElapsed < targetDistance)
{
// Come to think of it I once read an article saying we
// were doing our integration wrong. Please look that up?
float dx = vx * dt;
float dy = vy * dt;
// Easy optimization when I have the time - avoid the sqrt!
distanceElapsed += sqrt(dx*dx + dy*dy);
PhysicsComponent* p = (PhysicsComponent*)Services::componentManager()
->gameObjGetComponentOfType(targetObjectID, ComponentType::PHYSICS);
// Why does PhysicsComponent not have a "add to" method?
// Implement later
p->newx(p->getx() + dx);
p->newy(p->gety() + dy);
}
else
{
// distanceElapsed >= targetDistance, so finalize
deactivate();
}
}
void MoveProcess::start()
{
}
void MoveProcess::onFinish()
{
// CallBack
cout << "Callback time!" << endl;
LuaCallbackProcess::onFinish();
// Free dependency
Services::componentManager()->gameObjRemoveDependency(targetObjectID);
}