{
paused_ = false;
- pScene_ = new QGraphicsScene ();
+ pScene_ = new SeaScene ();
pView_ = new QGraphicsView ();
QPixmap waves (":/pix/meri.png");
pScene_->setBackgroundBrush(QBrush(waves));
- pTursas_ = new OrientationControlledGraphicsPixmapObject(QPixmap(":/pix/tursas.png"));
+ pTursas_ = new OrientationControlledGraphicsPixmapObject(QPixmap(":/pix/laiva.png"));
pScene_->addItem(pTursas_);
pView_->setScene(pScene_);
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 * 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);
pTursas_->startMoving();
qDebug() << "Initialized boundaries" << rectangle.left() << rectangle.right() << pView_->width();
+
+ pScene_->setupMap(5,5,5);
}
void MainWindow::pause(bool paused)
#include <QtGui/QMainWindow>
#include <QGraphicsView>
#include "orientationcontrolledgraphicspixmapobject.h"
+#include "seascene.h"
class MainWindow : public QMainWindow
{
private:
-QGraphicsScene * pScene_;
+SeaScene * pScene_;
QGraphicsView * pView_;
OrientationControlledGraphicsPixmapObject * pTursas_;
bool paused_;
SOURCES += main.cpp\
mainwindow.cpp \
orientationcontrolledgraphicspixmapobject.cpp \
- timercontrolledtursas.cpp
+ timercontrolledtursas.cpp \
+ seascene.cpp \
+ seaview.cpp
HEADERS += mainwindow.h \
orientationcontrolledgraphicspixmapobject.h \
- timercontrolledtursas.h
+ timercontrolledtursas.h \
+ seascene.h \
+ seaview.h
CONFIG += mobility
MOBILITY = sensors
RESOURCES += \
orientationcontrol2pix.qrc
+
+maemo5 {
+ desktopfile.files = $${TARGET}.desktop
+ desktopfile.path = /usr/share/applications/hildon
+ INSTALLS += desktopfile
+}
--- /dev/null
+#include "seascene.h"
+#include <QGraphicsPixmapItem>
+#include <QDebug>
+
+const QString ghostImageFilename_ = ":/pix/aave.png";
+const QString rockImageFilename_ =":/pix/kari.png";
+const QString octopusImageFilename_= ":/pix/tursas.png";
+
+
+SeaScene::SeaScene(QObject *parent) :
+ QGraphicsScene(parent)
+{
+
+
+}
+
+void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
+{
+ //empty the list of free slots
+ freeTiles_.clear();
+
+ //fill the list of free slots
+
+ int numberOfXTiles = width() / 40;
+ int numberOfYTiles = height() /40;
+
+ qDebug() << numberOfXTiles << " slots in x direction";
+ qDebug() << numberOfYTiles << " slots in y rirection";
+
+ for (int i = 0; i < numberOfXTiles; i++ )
+ {
+ for (int j = 0; j < numberOfYTiles; j++)
+ {
+ freeTiles_.append(QPointF(i*40,j*40));
+ }
+ }
+ spreadGhosts(ghosts);
+}
+
+void SeaScene::spreadGhosts(int ghosts)
+{
+ for (int i=0; i < ghosts; i++)
+ {
+ QPointF position = findRandomFreeSlot();
+
+ QGraphicsPixmapItem * pGhost = addPixmap(QPixmap(":/pix/aave.png"));
+ pGhost->setData(0,"ghost");
+ pGhost->setPos(position);
+ }
+}
+
+QPointF SeaScene::findRandomFreeSlot()
+{
+ int index = qrand()%freeTiles_.size();
+
+ qDebug() << index << " index";
+ return freeTiles_.takeAt(index);
+
+}
--- /dev/null
+#ifndef SEASCENE_H
+#define SEASCENE_H
+
+#include <QGraphicsScene>
+
+class SeaScene : public QGraphicsScene
+{
+ Q_OBJECT
+public:
+ explicit SeaScene(QObject *parent = 0);
+
+signals:
+
+public slots:
+
+ void setupMap(int ghosts, int rocks, int octopuses);
+
+ void spreadGhosts(int ghosts);
+
+protected:
+
+ QPointF findRandomFreeSlot();
+
+ const QString ghostImageFilename_;
+ const QString rockImageFilename_;
+ const QString octopusImageFilename_;
+ const QStringList shipImageFilenames_;
+
+ QList<QPointF> freeTiles_;
+
+
+
+
+};
+
+#endif // SEASCENE_H
//Bound the item into the scene and change direction if hitting a boundary
+ //Only works if the old position is inside the boundaries
if (!scene()) //no movement if this item does not belong to a scene
return;