diff options
author | Geir Vattekar <geir.vattekar@trolltech.com> | 2009-05-07 13:56:50 (GMT) |
---|---|---|
committer | Geir Vattekar <geir.vattekar@trolltech.com> | 2009-05-07 13:56:50 (GMT) |
commit | 90057dabcb99759bcb42c1c21db7151c69d98706 (patch) | |
tree | c2215154650ea6ec0d9ad13cb4271cca55a62449 /examples/statemachine/errorstate/gameitem.cpp | |
parent | 2a410483a29c0e821588fd94c3179f7ab775ebbf (diff) | |
parent | 8b57ae82ef507db1912a35fbe5d60f2cc3668cdb (diff) | |
download | Qt-90057dabcb99759bcb42c1c21db7151c69d98706.zip Qt-90057dabcb99759bcb42c1c21db7151c69d98706.tar.gz Qt-90057dabcb99759bcb42c1c21db7151c69d98706.tar.bz2 |
Merge branch 'kinetic-animations' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-animations
Diffstat (limited to 'examples/statemachine/errorstate/gameitem.cpp')
-rw-r--r-- | examples/statemachine/errorstate/gameitem.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/examples/statemachine/errorstate/gameitem.cpp b/examples/statemachine/errorstate/gameitem.cpp index 786cf51..1a2af71 100644 --- a/examples/statemachine/errorstate/gameitem.cpp +++ b/examples/statemachine/errorstate/gameitem.cpp @@ -1,6 +1,11 @@ #include "gameitem.h" #include <QGraphicsScene> +#include <QDebug> + +GameItem::GameItem(QObject *parent) : QObject(parent) +{ +} QPointF GameItem::tryMove(const QPointF &requestedPosition, QLineF *collidedLine, QGraphicsItem **collidedItem) const @@ -52,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; } |