Now stops at rocks.
//the boundaries of the scene are set to match the size of the view window, which is not
//available in the constructor --> timer needed
- QTimer::singleShot(60,this,SLOT(initializeBoundaries()));
+ QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
QAction * pPauseAction = new QAction(tr("Pause"),this);
connect(pPauseAction,SIGNAL(triggered(bool)),this,SLOT(pause(bool)));
menuBar()->addAction(pPauseAction);
+ QGraphicsPixmapItem * pGhost = pScene_->addPixmap(QPixmap(":/pix/aave.png"));
+ pGhost->setData(0,"ghost");
+ QGraphicsPixmapItem * pRock = pScene_->addPixmap(QPixmap(":/pix/kari.png"));
+ QGraphicsPixmapItem * pRock2 = pScene_->addPixmap(QPixmap(":/pix/kari.png"));
+ pRock->moveBy(40,40);
+ pRock->setData(0,"rock");
+ pRock2->moveBy(80,80);
+ pRock2->setData(0,"rock");
+
+
}
MainWindow::~MainWindow()
<qresource prefix="/pix">
<file>meri.png</file>
<file>tursas.png</file>
+ <file>kari.png</file>
+ <file>aave.png</file>
</qresource>
</RCC>
// qDebug() << deltax << " " << deltay;
+ int oldx = x();
+ int oldy = y();
+
int newx = x() + deltax/15;
int newy = y() + deltay/15;
setX(qBound(sceneRectangle.left(),newx,sceneRectangle.right()-pixmap().width()));
setY(qBound(sceneRectangle.top(),newy,sceneRectangle.bottom()-pixmap().height()));
+ QList<QGraphicsItem*> collidesList = collidingItems();
+ if (!collidesList.isEmpty())
+ {
+ qDebug() << collidesList.at(0)->data(0);
+ if (collidesList.at(0)->data(0) == "rock")
+ {
+ setX(oldx);
+ setY(oldy);
+ }
+ }
+
}
}
+void OrientationControlledGraphicsPixmapObject::setObstacles(int key, QList<QVariant> values)
+{
+ obstacleKey_ = key;
+ obstacleValues_ = values;
+}
+
QTM_USE_NAMESPACE
+
class OrientationControlledGraphicsPixmapObject : public QObject, public QGraphicsPixmapItem
{
Q_OBJECT
void readRotationSensor();
void setBoundaries(QRectF boundaryrect);
+ /*! sets what QGraphicsItems to treat as obstacles not to move on top of
+ @param key The key to be used with QGraphicsItem::data() to find the correct value to compare
+ @param values The values received from QGraphicsItem::data() to treat as obstacles
+ */
+ void setObstacles(int key, QList<QVariant> values);
+
private:
QRectF boundaryrect_;
+ int obstacleKey_;
+ QList<QVariant> obstacleValues_;
+
};
#endif // ORIENTATIONCONTROLLEDGRAPHICSPIXMAPOBJECT_H