diff options
author | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-05-05 12:50:56 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-05-05 12:50:56 (GMT) |
commit | 6de0b13042f39b7570588eb5615cc1e16a71eced (patch) | |
tree | 237d819e02bf394b7ee00f4c9c356f1f254a2814 /examples/statemachine | |
parent | 8b4daee4bd6c6dd3da7b7e71b6c468059cf53ea0 (diff) | |
download | Qt-6de0b13042f39b7570588eb5615cc1e16a71eced.zip Qt-6de0b13042f39b7570588eb5615cc1e16a71eced.tar.gz Qt-6de0b13042f39b7570588eb5615cc1e16a71eced.tar.bz2 |
Set collidedLine for the implicit walls around the scene to allow for collision
response.
Diffstat (limited to 'examples/statemachine')
-rw-r--r-- | examples/statemachine/errorstate/gameitem.cpp | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/examples/statemachine/errorstate/gameitem.cpp b/examples/statemachine/errorstate/gameitem.cpp index d286df4..1a2af71 100644 --- a/examples/statemachine/errorstate/gameitem.cpp +++ b/examples/statemachine/errorstate/gameitem.cpp @@ -1,6 +1,7 @@ #include "gameitem.h" #include <QGraphicsScene> +#include <QDebug> GameItem::GameItem(QObject *parent) : QObject(parent) { @@ -56,15 +57,31 @@ QPointF GameItem::tryMove(const QPointF &requestedPosition, QLineF *collidedLine } } + // Don't go outside of map - if (nextPoint.x() < sceneRect.left()) + if (nextPoint.x() < sceneRect.left()) { nextPoint.rx() = sceneRect.left(); - if (nextPoint.x() > sceneRect.right()) + if (collidedLine != 0) + *collidedLine = QLineF(scene()->sceneRect().topLeft(), scene()->sceneRect().bottomLeft()); + } + + if (nextPoint.x() > sceneRect.right()) { nextPoint.rx() = sceneRect.right(); - if (nextPoint.y() < sceneRect.top()) + if (collidedLine != 0) + *collidedLine = QLineF(scene()->sceneRect().topRight(), scene()->sceneRect().bottomRight()); + } + + if (nextPoint.y() < sceneRect.top()) { nextPoint.ry() = sceneRect.top(); - if (nextPoint.y() > sceneRect.bottom()) + if (collidedLine != 0) + *collidedLine = QLineF(scene()->sceneRect().topLeft(), scene()->sceneRect().topRight()); + } + + if (nextPoint.y() > sceneRect.bottom()) { nextPoint.ry() = sceneRect.bottom(); + if (collidedLine != 0) + *collidedLine = QLineF(scene()->sceneRect().bottomLeft(), scene()->sceneRect().bottomRight()); + } return nextPoint; } |