summaryrefslogtreecommitdiffstats
path: root/examples/statemachine/errorstate/tankitem.h
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-04-24 15:35:35 (GMT)
committerEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-04-24 15:41:43 (GMT)
commitc3290381a1dba7971dd70b7220a71e6feceb3f4c (patch)
tree136f68ab9da00b4571118f18875b3d53928eee46 /examples/statemachine/errorstate/tankitem.h
parentdfe6974c1e7103ad46fa1162d7c9fd6a426894b7 (diff)
downloadQt-c3290381a1dba7971dd70b7220a71e6feceb3f4c.zip
Qt-c3290381a1dba7971dd70b7220a71e6feceb3f4c.tar.gz
Qt-c3290381a1dba7971dd70b7220a71e6feceb3f4c.tar.bz2
Unfinished tank AI game. The idea is that you plug in AIs for the tanks, and
one such plugin will have a run time error, so the game server needs to use errorState for handling errors.
Diffstat (limited to 'examples/statemachine/errorstate/tankitem.h')
-rw-r--r--examples/statemachine/errorstate/tankitem.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/statemachine/errorstate/tankitem.h b/examples/statemachine/errorstate/tankitem.h
new file mode 100644
index 0000000..df13689
--- /dev/null
+++ b/examples/statemachine/errorstate/tankitem.h
@@ -0,0 +1,48 @@
+#ifndef TANKITEM_H
+#define TANKITEM_H
+
+#include "tank.h"
+
+#include <QGraphicsItem>
+#include <QColor>
+
+class Action;
+class TankItem: public Tank, public QGraphicsItem
+{
+ Q_OBJECT
+public:
+ TankItem(QObject *parent = 0);
+
+ virtual void moveForwards(qreal length);
+ virtual void moveBackwards(qreal length);
+ virtual void turn(qreal newDirection);
+ virtual void stop();
+ virtual void fireCannon(qreal distance);
+ virtual qreal direction() const;
+ virtual qreal distanceToObstacle() const;
+
+ void setColor(const QColor &color) { m_color = color; }
+ QColor color() const { return m_color; }
+
+ void idle(qreal elapsed);
+ void setDirection(qreal newDirection);
+
+ qreal speed() const { return 20.0; }
+ qreal angularSpeed() const { return 1.0; }
+
+protected:
+ virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
+ QRectF boundingRect() const;
+ QVariant itemChange(QGraphicsItem::GraphicsItemChange change, const QVariant &value);
+
+private:
+ QPointF tryMove(const QPointF &requestedPosition) const;
+ void setAction(Action *newAction);
+
+ Action *m_currentAction;
+ qreal m_currentDirection;
+ QColor m_color;
+ mutable QPolygonF m_brp;
+};
+
+#endif