summaryrefslogtreecommitdiffstats
path: root/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp
diff options
context:
space:
mode:
authorEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-05-12 14:40:44 (GMT)
committerEskil Abrahamsen Blomfeldt <eblomfel@trolltech.com>2009-05-12 14:42:26 (GMT)
commitd26a56e2d94bea2b5a1135b8336bbeefebf3ba1c (patch)
treec4a6497357266aa6f8bca69aef985a0f4ac5779d /examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp
parentcb516fd65149991a2105c545192a52f26a6ab67d (diff)
downloadQt-d26a56e2d94bea2b5a1135b8336bbeefebf3ba1c.zip
Qt-d26a56e2d94bea2b5a1135b8336bbeefebf3ba1c.tar.gz
Qt-d26a56e2d94bea2b5a1135b8336bbeefebf3ba1c.tar.bz2
Change name of "errorstate" example to "tankgame"
The error state is not a big enough part of the example to justify naming it after it.
Diffstat (limited to 'examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp')
-rw-r--r--examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp
new file mode 100644
index 0000000..2fb05d4
--- /dev/null
+++ b/examples/statemachine/tankgameplugins/seek_ai/seek_ai.cpp
@@ -0,0 +1,48 @@
+#include "seek_ai.h"
+
+QState *SeekAi::create(QState *parentState, QObject *tank)
+{
+ QState *topLevel = new QState(parentState);
+ topLevel->setObjectName("topLevel");
+
+ QState *seek = new QState(topLevel);
+ seek->setObjectName("seek");
+ topLevel->setInitialState(seek);
+
+ QState *lookForNearestWall = new SearchState(tank, seek);
+ lookForNearestWall->setObjectName("lookForNearestWall");
+ seek->setInitialState(lookForNearestWall);
+
+ QState *driveToFirstObstacle = new QState(seek);
+ driveToFirstObstacle->setObjectName("driveToFirstObstacle");
+ lookForNearestWall->addTransition(lookForNearestWall, SIGNAL(nearestObstacleStraightAhead()),
+ driveToFirstObstacle);
+
+ QState *drive = new QState(driveToFirstObstacle);
+ drive->setObjectName("drive");
+ driveToFirstObstacle->setInitialState(drive);
+ connect(drive, SIGNAL(entered()), tank, SLOT(moveForwards()));
+ connect(drive, SIGNAL(exited()), tank, SLOT(stop()));
+
+ // Go in loop
+ QState *finishedDriving = new QState(driveToFirstObstacle);
+ finishedDriving->setObjectName("finishedDriving");
+ drive->addTransition(tank, SIGNAL(actionCompleted()), finishedDriving);
+ finishedDriving->addTransition(drive);
+
+ QState *turnTo = new QState(seek);
+ turnTo->setObjectName("turnTo");
+ driveToFirstObstacle->addTransition(new CollisionTransition(tank, turnTo));
+
+ turnTo->addTransition(tank, SIGNAL(actionCompleted()), driveToFirstObstacle);
+
+ ChaseState *chase = new ChaseState(tank, topLevel);
+ chase->setObjectName("chase");
+ seek->addTransition(new TankSpottedTransition(tank, chase));
+ chase->addTransition(chase, SIGNAL(finished()), driveToFirstObstacle);
+ chase->addTransition(new TankSpottedTransition(tank, chase));
+
+ return topLevel;
+}
+
+Q_EXPORT_PLUGIN2(seek_ai, SeekAi)