-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdynamicobject.cpp
101 lines (79 loc) · 2.69 KB
/
dynamicobject.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
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "dynamicobject.h"
namespace SSJServer {
DynamicObject::DynamicObject(): InteractiveObject()
{
this->velocity = 0.0;
this->angle = 0.0;
this->targetAngle = 0.0;
}
size_t DynamicObject::getVelocity() const
{
return velocity;
}
void DynamicObject::setVelocity(const size_t &value)
{
velocity = value;
}
void DynamicObject::MoveForward(){
this->setMapPosition(CalcNewPosition(this->angle+0));
}
void DynamicObject::MoveBackward(){
this->setMapPosition(CalcNewPosition(this->angle+180));
}
void DynamicObject::MoveLeft(){
this->setMapPosition(CalcNewPosition(this->angle+270));
}
void DynamicObject::MoveRight(){
this->setMapPosition(CalcNewPosition(this->angle+90));
}
void DynamicObject::RotateLeft(){
float deltaAngle = Config::RotationSpeed * DataContainer::DeltaTime.asSeconds();
bool a;
if(this->targetAngle.getDegrees() - this->angle.getDegrees() < 0)
a = true;
else
a = false;
/** czy przeszło przez zero by Łysy**/
if(this->angle.getDegrees() * (this->angle.getDegrees() - deltaAngle) < 0){
a = !a;
}
if(((this->targetAngle.getDegrees() - this->angle.getDegrees()- deltaAngle ) < 0 ) != a)
this->angle = this->targetAngle;
else
this->angle -= deltaAngle;
}
void DynamicObject::RotateRight(){
float deltaAngle = Config::RotationSpeed * DataContainer::DeltaTime.asSeconds();
bool a;
if(this->targetAngle.getDegrees() - this->angle.getDegrees() < 0)
a = true;
else
a = false;
/** czy przeszło przez zero by Łysy**/
if(this->angle.getDegrees() * (this->angle.getDegrees() + deltaAngle) < 0){
a = !a;
}
if(((this->targetAngle.getDegrees() - this->angle.getDegrees() + deltaAngle ) < 0 ) != a)
this->angle = this->targetAngle;
else
this->angle += deltaAngle;
}
Point DynamicObject::CalcNewPosition(SSJServer::Degrees addAngle){
Point newPosition = this->getMapPosition();
SSJServer::Degrees tempDegrees = this->angle;
tempDegrees += addAngle;
float s = this->velocity * DataContainer::DeltaTime.asSeconds();
float px = sin(tempDegrees.getRadians()) * s;
float py = cos(tempDegrees.getRadians()) * s;
newPosition.x += px;
newPosition.y -= py;
return newPosition;
}
Degrees DynamicObject::getAngle(){
return this->angle;
}
Json::Value DynamicObject::serialize()
{
return Json::nullValue;
}
}