~mzanetti/machines-vs-machines/qmake-based

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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef TOWER_H
#define TOWER_H

#include <QObject>
#include <QPoint>

class Board;
class Engine;
class Enemy;

class TowerConfig {
public:
    int cost;
    QString image;
    int spriteCount;
    qreal frameRate;
    QString shotImage;
    QString shotType;
    int damage;
    int shotDuration;
    int shotRecovery;
    int shotCount;
    QPoint shotCenter;
    int shotStartDistance;
    qreal radius;
    int slowdown;
    bool locked;
    int unlockPoints;
};

class Tower : public QObject
{
    Q_OBJECT
    Q_ENUMS(ShotType)

    Q_PROPERTY(int id READ id CONSTANT)
    Q_PROPERTY(QString name READ name NOTIFY nameChanged)
    Q_PROPERTY(int levels READ levels NOTIFY levelsChanged)
    Q_PROPERTY(int level READ level NOTIFY levelChanged)
    Q_PROPERTY(QString image READ image NOTIFY levelChanged)
    Q_PROPERTY(int spriteCount READ spriteCount NOTIFY levelChanged)
    Q_PROPERTY(qreal frameRate READ frameRate NOTIFY levelChanged)
    Q_PROPERTY(QString shotImage READ shotImage NOTIFY levelChanged)
    Q_PROPERTY(ShotType shotType READ shotType NOTIFY levelChanged)
    Q_PROPERTY(qreal radius READ radius NOTIFY levelChanged)
    Q_PROPERTY(int shotDuration READ shotDuration NOTIFY levelChanged)
    Q_PROPERTY(bool canShoot READ canShoot NOTIFY levelChanged)
    Q_PROPERTY(int shotCount READ shotCount NOTIFY levelChanged)
    Q_PROPERTY(QPoint shotCenter READ shotCenter NOTIFY levelChanged)
    Q_PROPERTY(int shotStartDistance READ shotStartDistance NOTIFY levelChanged)
    Q_PROPERTY(int damage READ damage NOTIFY levelChanged)
    Q_PROPERTY(int slowdown READ slowdown NOTIFY levelChanged)

public:
    enum ShotType {
        ShotTypeSingle,
        ShotTypeBeam
    };

    explicit Tower(int id, Engine *engine, QObject *parent = 0);
    void upgrade();

    int id() const;

    QString name() const;
    void setName(const QString &name);

    void setConfigs(const QList<TowerConfig> &configs);
    int levels() const;
    int level() const;

    QString image() const;
    int spriteCount() const;
    qreal frameRate() const;

    QString shotImage() const;
    ShotType shotType() const;

    qreal radius() const;

    int shotDuration() const;
    bool canShoot() const;

    int shotCount() const;
    QPoint shotCenter() const;
    int shotStartDistance() const;

    int damage() const;

    int slowdown() const;

    QList<TowerConfig> configs();

public slots:
    void shoot(Enemy *enemy);

signals:
    void nameChanged();
    void levelsChanged();
    void levelChanged();

private slots:
    void recoverFromShot();

private:
    int m_id;
    Engine *m_engine;
    QString m_name;
    int m_level;
    QList<TowerConfig> m_configs;
    bool m_canShoot;
};

#endif // TOWER_H