-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmovevector.cpp
More file actions
42 lines (37 loc) · 792 Bytes
/
movevector.cpp
File metadata and controls
42 lines (37 loc) · 792 Bytes
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
#include "movevector.h"
MoveVector::MoveVector()
{
for(int i=0;i<5;++i){
StateofMoveKeys[i]=QString("unpressed");
}
toZeroVector();
}
void MoveVector::toZeroVector(){
Vx=Vy=0;
}
void MoveVector::movex(qreal dx){
Vx+=dx;
}
void MoveVector::movey(qreal dy){
Vy+=dy;
}
void MoveVector::GenerateVector(){
toZeroVector();
if(StateofMoveKeys[0]==QString("pressed")){
movex(1.0);
}
if(StateofMoveKeys[1]==QString("pressed")){
movey(-1.0);
}
if(StateofMoveKeys[2]==QString("pressed")){
movex(-1.0);
}
if(StateofMoveKeys[3]==QString("pressed")){
movey(1.0);
}
qreal length=qSqrt(Vx*Vx+Vy*Vy);
if(length!=qreal(0.0)){//归一至单位向量
Vx/=length;
Vy/=length;
}
}