Repository navigation
Expand file tree
/
Copy pathTrain.cpp
More file actions
65 lines (54 loc) · 1.88 KB
/
Copy pathTrain.cpp
File metadata and controls
65 lines (54 loc) · 1.88 KB
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
#include "Train.h"
void Train::Update(const sf::Input &input) {
static sf::Clock clock;
static bool waiting = false;
acceleration = (1/mass) *(push_force - speed * brakes_factor);
speed += acceleration;
position.z += speed;
if (position.z > 900 || position.z < -900) {
position.z = -position.z;
//comingSound.SetPosition(this->position);
comingSound.Play();
StopGas();
}
if (!user_controlled){
if (position.z < -250 && position.z > -300){
StopGas();
Brakes();
}
if (IsStopped() && !waiting){
clock.Reset();
alarm=false;
waiting = true;
printf("\n\n\n waiting\n");
}
if (waiting && clock.GetElapsedTime() > waiting_time) {
Gas();
waiting = false;
printf(" timed out\n");
}
if (waiting && clock.GetElapsedTime() > waiting_time-4 && !alarm) {
alarm=true;
sound.SetBuffer(Buffer);
//sound.SetPitch(0.6);
//sound.SetAttenuation(0.4);
sound.SetRelativeToListener(true);
sound.SetPosition(this->position);
sound.SetMinDistance(100);
sound.Play();
//movmetnSound.SetPosition(this->position);
movmetnSound.Play();
}
light->position = sf::Vector3f(-40.900002,10,position.z + 5) ;
if(camera !=NULL)
camera->SetOrigin(position.x+8.3,position.y+15,position.z);
}else {
if (input.IsKeyDown(sf::Key::Z)) {
push_force = 0.1f;
}else if (input.IsKeyDown(sf::Key::X)){
brakes_factor = 0.05f;
}
}
}
Train::~Train() {
}