-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmovevector.cpp
57 lines (51 loc) · 911 Bytes
/
movevector.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
#include "movevector.h"
MoveVector::MoveVector()
{
init();
}
void MoveVector::init()
{
for(int i=0;i<5;i++)
{
this->MoveKeysPressed[i]=false;
}
this->toZeroVector();
}
void MoveVector::toZeroVector()
{
this->Vx=0;
this->Vy=0;
}
void MoveVector::GenerateVector()
{
if(this->MoveKeysPressed[0])//left
{
this->AddVx(-1.0);
}
if(this->MoveKeysPressed[1])//up
{
this->AddVy(-1.0);
}
if(this->MoveKeysPressed[2])//down
{
this->AddVy(1.0);
}
if(this->MoveKeysPressed[3])//right
{
this->AddVx(1.0);
}
qreal length=qSqrt(this->Vx*this->Vx+this->Vy*this->Vy);
if(length!=qreal(0.0))
{
this->Vx=this->Vx/length;
this->Vy=this->Vy/length;
}
}
void MoveVector::AddVx(qreal deltax)
{
this->Vx+=deltax;
}
void MoveVector::AddVy(qreal deltay)
{
this->Vy+=deltay;
}