-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcar.h
52 lines (45 loc) · 1.24 KB
/
car.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
#ifndef CAR_H
#define CAR_H
#include <QGraphicsItem>
#include <QPainter>
#include <chrono>
#include "mymath.h"
#include "roadpoint.h"
const float CAR_LENGTH = 10;
const float CAR_WIDTH = 5;
const int UPDATES_PER_SECOND = 60;
const float TICK_TIME = 1000.0 / UPDATES_PER_SECOND;
const float MAX_SPEED = 6;
const QColor colors[4] = {QColor(255, 0, 0),
QColor(0, 255, 0),
QColor(0, 0, 255),
QColor(255, 20, 147)};
class Car : public QObject, public QGraphicsItem
{
Q_OBJECT
private:
RoadPoint pos;
float angle;
float velocity;
QTimer* timer;
QColor color;
public:
Car(const Car& other);
Car(Car&& other) noexcept;
Car(RoadPoint pos, float angle);
~Car() override;
void Rotate(float delta);
void setVelocity(float newVelocity);
void setLevel(int newLevel);
void Update();
void ConnectTimer();
RoadPoint GetPosition() const;
RoadPoint PredictPosition() const;
float GetAngle() const;
float GetVelocity() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
QRectF boundingRect() const override;
signals:
void needToUpdateLevelOfCar();
};
#endif // CAR_H