-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentity.h
84 lines (71 loc) · 2.11 KB
/
entity.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
77
78
79
80
81
82
83
84
#ifndef ENTITY_H
#define ENTITY_H
#include <QGraphicsObject>
//!
//! \brief The Entity class - abstract class with some standard methods defined to be used in the exe loop
//!
class Entity : public QGraphicsObject
{
Q_OBJECT
public:
Entity(QGraphicsItem *parent = nullptr);
virtual ~Entity() = default;
virtual void init() = 0;
virtual void update(int dt);
void setTimescale(const qreal ×cale);
public slots:
void setPosX(int x);
void setAngle(int x);
void setVel(const qreal &v);
void setGravity(const qreal &g);
protected:
qreal vel_;
qreal angle_;
qreal gravity_;
qreal timescale_;
};
//!
//! \brief The Tank class - the shooting entity, it is possible to move it horizontally and change the launch angle
//!
class Tank : public Entity
{
Q_OBJECT
public:
Tank(QGraphicsItem *parent = nullptr);
~Tank() override = default;
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
QPointF cannonPos();
// Entity interface
public:
void init() override;
private:
QVector<QPoint> points_;
QPointF cannonPos_;
};
//!
//! \brief The Projectile class - a small triangle tha is projected from the tank, it is the entity that implements
//! the projectile equations
//! most of the equations came from here: https://en.wikipedia.org/wiki/Projectile_motion
//!
class Projectile : public Entity
{
Q_OBJECT
public:
Projectile(QGraphicsItem *parent = nullptr);
~Projectile() override = default;
QRectF boundingRect() const override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override;
// Entity interface
public:
void update(int dt) override;
void init() override;
private:
QVector<QPoint> points_;
qreal time_; // advances animation timing
qreal vx_; // starting velocity in x, calculated
qreal vy_; // starting velocity in y, calculated
qreal x_; // current position in x, calculated
qreal y_; // current position in y, calculated
};
#endif // ENTITY_H