summaryrefslogtreecommitdiffstats
path: root/examples/statemachine/tankgameplugins/spin_ai/spin_ai.h
blob: a331a3e283e382b44fa39656d5fb81a89578351e (plain)
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
#ifndef SPIN_AI_H
#define SPIN_AI_H

#include <tankgame/plugin.h>

#include <QObject>
#include <QState>
#include <QVariant>

class SpinState: public QState
{
    Q_OBJECT
public:
    SpinState(QObject *tank, QState *parent) : QState(parent), m_tank(tank)
    {
    }

public slots:
    void spin() 
    {
        m_tank->setProperty("direction", 90.0);
    }

protected:
    void onEntry(QEvent *)
    {
        connect(m_tank, SIGNAL(actionCompleted()), this, SLOT(spin()));
        spin();        
    }

private:
    QObject *m_tank;

};

class SpinAi: public QObject, public Plugin
{
    Q_OBJECT
    Q_INTERFACES(Plugin)
public:
    SpinAi() { setObjectName("Spin and destroy"); }

    virtual QState *create(QState *parentState, QObject *tank);
};

#endif