-
Notifications
You must be signed in to change notification settings - Fork 0
/
ActionMoveTo.cpp
52 lines (45 loc) · 1.23 KB
/
ActionMoveTo.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 "ActionMoveTo.h"
ActionMoveTo::ActionMoveTo(Game::Object **_aim, float _timeDiference, const Vector2D& _radius,
const Vector2D& _tolerance, bool _useLayerX, bool _useLayerY, const initializer_list< pair<Action*, float> >& _initializer)
: aim(_aim), timeDiference(_timeDiference), radius(_radius), tolerance(_tolerance), useLayerX(_useLayerX), useLayerY(_useLayerY)
, Action(_initializer)
{
}
ActionMoveTo::ActionMoveTo(const Vector2D& _position, const Vector2D& _radius, const Vector2D& _tolerance)
: aim(nullptr), position(_position), radius(_radius), tolerance(_tolerance)
{
}
void ActionMoveTo::update(float dt)
{
if (aim != nullptr)
{
if (*aim != nullptr)
{
Vector2D rad = radius;
float myRadius = owner->layerCollider.collider.range;
float enemyRadius = (*aim)->layerCollider.collider.range;
if (useLayerX)
{
rad.x += myRadius;
rad.y += myRadius;
}
if (useLayerY)
{
rad.x += enemyRadius;
rad.y += enemyRadius;
}
isDone = owner->moveTo(*aim, timeDiference, rad, tolerance);
}
}
else
{
isDone = owner->moveTo(position, radius, tolerance);
}
}
bool ActionMoveTo::done()
{
return isDone;
}
/*void ActionMoveTo::reset()
{
}*/