-
Notifications
You must be signed in to change notification settings - Fork 0
/
car.hpp
77 lines (54 loc) · 1.74 KB
/
car.hpp
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
#ifndef CAR_H
#define CAR_H
#include <SFML/Graphics.hpp>
#include <cAudio/cAudio.h>
const float CAR_WIDTH = 25;
const float HONK_STRENGTH = 100.0;
const float SWEAR_STRENGTH = 100.0;
const float ENGINE_NOISE_STRENGTH = 50.0;
class Car {
public:
/*
* Initializes a car with starting position pos, and velocity velocity.
* The car will travel as fast as the magnitude of velocity and in
* that direction.
*/
Car(cAudio::IAudioSource* source,
cAudio::IAudioSource* honk_audio_source,
cAudio::IAudioSource* swear_audio_source);
/*
* Moves the car one step in the direction of it's velocity.
*/
void update_position(float dt);
/*
* Starts the engine noise
*/
void start(sf::Vector2<float> pos, sf::Vector2<float> velocity);
/*
* Stops the engine noise.
*/
void stop();
sf::Vector2<float> get_position() const;
void honk_if_close_to(sf::Vector2<float> pos, float distance);
void swear_if_close_to(sf::Vector2<float> pos, float distance);
int get_road_index() const;
void set_road_index(int index);
/*
* Checks whether this car is colliding with something at position
* pos with width width.
*/
bool collides_with(sf::Vector2<float> pos) const;
bool out_of_bounds(int width, int height) const;
private:
sf::Vector2<float> pos;
sf::Vector2<float> velocity;
cAudio::IAudioSource* audio_source;
cAudio::IAudioSource* honk_audio_source;
cAudio::IAudioSource* swear_audio_source;
int road_index;
float honk_distance;
bool swore;
void play_if_close_to(sf::Vector2<float> pos,
float distance, cAudio::IAudioSource* sound, float strength);
};
#endif /* ifndef CAR_H */