-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDron.cpp
77 lines (70 loc) · 1.78 KB
/
Dron.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
#include "Dron.h"
Dron::Dron(sf::Vector2f position) : Ship("Dron.png", download(position)) {
assembly();
}
RigidBodyParameters Dron::download(sf::Vector2f position) {
std::ifstream fin("data/Dron.txt");
if (!fin.is_open()) { throw "Wrong file name"; }
RigidBodyParameters par;
par.position = position;
std::string str;
float x, y;
fin >> str >> par.width;
fin >> str >> par.height;
fin >> str >> par.angle;
fin >> str >> par.mass;
fin >> str >> par.moment_of_inertia;
fin >> str >> x >> y;
par.mass_position = Vector2f(x, y);
fin.close();
return par;
}
void Dron::assembly() {
AddEngine(Engine(Object("fire.png", Vector2f(10, 10), 0), Vector2f(0.5, 1),
Force(false, 400, Vector2f(0, -1), Vector2f(0.5, 1)), 10), "1");
AddEngine(Engine(Object("fireleft.png", Vector2f(0, 0),0), Vector2f(0.22, 0.87),
Force(false, 100, Vector2f(-0.5, -1), Vector2f(0, 0.5)), 10), "2");
AddEngine(Engine(Object("fireright.png", Vector2f(0, 0), 0), Vector2f(0.78, 0.87),
Force(false, 100, Vector2f(0.5, -1), Vector2f(1, 0.5)), 10), "3");
}
void Dron::control() {
if (status != 0 && status != 1) {
for (auto& i : engines) { EngineOff(i.first); }
return;
}
if (Keyboard::isKeyPressed(Keyboard::W)) {
EngineOn("1");
}
else {
EngineOff("1");
}
if (Keyboard::isKeyPressed(Keyboard::A)) {
EngineOn("2");
}
else {
EngineOff("2");
}
if (Keyboard::isKeyPressed(Keyboard::D)) {
EngineOn("3");
}
else {
EngineOff("3");
}
if (Keyboard::isKeyPressed(Keyboard::LShift)) {
SetEngineThrust("1", 0.5);
}
else if (Keyboard::isKeyPressed(Keyboard::LControl)) {
SetEngineThrust("1", 2);
}
else {
SetEngineThrust("1", 1);
}
}
void Dron::DrawShip(RenderWindow& window) const {
Draw(window);
for (const auto& e : engines) {
if (e.second.If_on()) {
e.second.Draw(window);
}
}
}