-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerMissile.cpp
58 lines (48 loc) · 1.04 KB
/
PlayerMissile.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
53
54
55
56
57
58
//Programmer: Axel Rotter Morgado
//Date: 18.04.2016
#include "PlayerMissile.h"
PlayerMissile::PlayerMissile(Vec2 EndPosition)
:EndPos(EndPosition)
{
StartPos.x = 432;
StartPos.y = 498;
CurrPos = StartPos;
Direction = CalcDirection(StartPos, EndPos);
}
//Method that checks if a Missile has detonated.
bool PlayerMissile::CheckDetonation()
{
if (CurrPos.y < EndPos.y)
{
return true;
}
else
{
return false;
}
}
//Method that updates the position of a missile
Vec2 PlayerMissile::UpdatePosition(float time)
{
CurrPos += Direction * time;
return CurrPos;
}
Vec2 PlayerMissile::GetCurrPos()
{
return CurrPos;
}
Vec2 PlayerMissile::GetEndPos()
{
return EndPos;
}
//Calculate the direction a missile should go with the
//starting and ending positions set in the constructor.
Vec2 PlayerMissile::CalcDirection(Vec2 StartPos, Vec2 EndPos)
{
Vec2 tempDir;
tempDir.x = EndPos.x - StartPos.x;
tempDir.y = EndPos.y - StartPos.y;
tempDir.normalize();
tempDir *= 300;
return tempDir;
}