-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroad.h
76 lines (51 loc) · 1.41 KB
/
road.h
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
#ifndef ROAD_H
#define ROAD_H
#include <QOpenGLWidget>
#include <QRandomGenerator>
#include <QOpenGLFunctions>
#include <QTimer>
#include <vector>
#include "car.h"
class Road : public QOpenGLWidget
{
Q_OBJECT
public:
Road(QWidget* parent = nullptr);
enum RoadPreset {
DISABLED = 0, RAND_A, RAND_B, RAND_C, RAND_U
};
enum Direction {
UP, DOWN, LEFT, RIGHT
};
void setPreset(const RoadPreset, const Direction);
void setPaused(bool paused);
// used like a queue to keep track of cars that are on the road
std::vector<Car*> cars;
void clear();
static float speed;
protected:
QTimer* timer;
// for temporal spawn gaps
QTimer* spawnTimer;
void paintGL();
void initializeGL();
void drawCar(Car* car);
RoadPreset preset;
Direction direction;
std::vector<qreal> gaps;
int currentCar;
bool paused;
// helper function to construct new cars with random parameters
virtual Car* createCar() = 0;
// before/after intersection and off-screen depend on the car's direction
virtual void updateRelativeLoc(Car*) = 0;
// distance between two cars depends on movement direction
virtual bool carsTooClose(Car*, Car*) = 0;
protected slots:
virtual void updateCars() = 0;
// construct a car and add it to the queue
void spawnCar();
private:
QOpenGLFunctions *openGLFunctions;
};
#endif // ROAD_H