~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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#ifndef ENEMY_H
#define ENEMY_H

#include <QObject>
#include <QHash>

class QTimer;
class Board;
class Engine;

class Enemy : public QObject
{
    Q_OBJECT
    Q_ENUMS(TravelStatus)
    Q_ENUMS(WalkingDirection)
    Q_PROPERTY(QString image READ image NOTIFY imageChanged)
    Q_PROPERTY(WalkingDirection walkingDirection READ walkingDirection NOTIFY walkingDirectionChanged)
    Q_PROPERTY(int spriteCount READ spriteCount NOTIFY imageChanged)
    Q_PROPERTY(qreal frameRate READ frameRate NOTIFY imageChanged)
    Q_PROPERTY(int x READ x NOTIFY currentFieldChanged)
    Q_PROPERTY(int y READ y NOTIFY currentFieldChanged)
    Q_PROPERTY(int currentField READ currentField NOTIFY currentFieldChanged)
    Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged)

    Q_PROPERTY(int nextX READ nextX NOTIFY currentFieldChanged)
    Q_PROPERTY(int nextY READ nextY NOTIFY currentFieldChanged)
    Q_PROPERTY(int nextField READ nextField NOTIFY currentFieldChanged)

    Q_PROPERTY(int speed READ speed NOTIFY speedChanged)
    Q_PROPERTY(int energy READ energy NOTIFY energyChanged)
    Q_PROPERTY(int maxEnergy READ maxEnergy NOTIFY maxEnergyChanged)

public:
    enum TravelStatus {
        TravelStatusEntry = -1,
        TravelStatusExit = -2,
        TravelStatusNoWayFound = -3,
    };

    enum WalkingDirection {
        WalkingDirectionLeft,
        WalkingDirectionRight,
        WalkingDirectionUp,
        WalkingDirectionDown
    };

    explicit Enemy(Engine *engine);

    QString image() const;
    int spriteCount() const;
    qreal frameRate() const;
    void setImage(const QString &image, int spriteCount = 1, qreal frameRate = 1);

    int x() const;
    int y() const;
    int currentField() const;

    int nextX() const;
    int nextY() const;
    int nextField() const;

    qreal progress() const;

    int speed() const;
    void setSpeed(int speed);

    void setEnergy(int energy);

    int reward() const;
    void setReward(int reward);

    int energy() const;
    int maxEnergy() const;

    Q_INVOKABLE qreal travelledDistance() const;

    WalkingDirection walkingDirection() const;

public slots:
    void advance();
    void hit(int damage, int slowDown, int delay);

signals:
    void imageChanged();
    void currentFieldChanged();
    void walkingDirectionChanged();
    void progressChanged();
    void speedChanged();
    void energyChanged(int energy);
    void maxEnergyChanged();
    void exited();
    void died();


private slots:
    void tick();
    void executeHit();
    void undoSlowdown();

private:
    Engine *m_engine;
    Board *m_board;
    QString m_image;
    WalkingDirection m_walkingDirection;
    int m_spriteCount;
    qreal m_frameRate;
    qreal m_progress;
    qreal m_travelledDistance;
    int m_currentField;
    int m_nextField;
    int m_speed;
    int m_energy;
    int m_maxEnergy;
    int m_reward;

    QList<int> m_slowdowns;

    class Hit {
    public:
        int damage;
        int slowDown;
    };

    QHash<QTimer*, Hit> m_hitList;
    QList<int> m_upcomingFields;
    QList<int> m_travelledFields;
};

#endif // ENEMY_H