From: Heli Hyvättinen Date: Mon, 6 Jun 2011 10:43:42 +0000 (+0300) Subject: Seascene map setup places rocks, octopuses and the ship now X-Git-Tag: v0.1.0~25 X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=3a02338078c3a0bdc20e3a9a60869ce09e06184f;p=ghostsoverboard Seascene map setup places rocks, octopuses and the ship now Also removed placing them from MainWindow. --- diff --git a/mainwindow.cpp b/mainwindow.cpp index d292082..e4ab78a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -19,9 +19,6 @@ MainWindow::MainWindow(QWidget *parent) QPixmap waves (":/pix/meri.png"); pScene_->setBackgroundBrush(QBrush(waves)); - pTursas_ = new OrientationControlledGraphicsPixmapObject(QPixmap(":/pix/laiva.png")); - pScene_->addItem(pTursas_); - pView_->setScene(pScene_); setCentralWidget(pView_); @@ -31,29 +28,6 @@ MainWindow::MainWindow(QWidget *parent) QTimer::singleShot(100,this,SLOT(initializeBoundaries())); - QAction * pPauseAction = new QAction(tr("Pause"),this); - pPauseAction->setCheckable(true); - addAction(pPauseAction); - 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"); - - TimerControlledTursas * pMustekala = new TimerControlledTursas (QPixmap(":/pix/tursas.png"),100); - pScene_->addItem(pMustekala); - pMustekala->moveBy(100,100); - pMustekala->startMoving(); - - - - } MainWindow::~MainWindow() @@ -73,8 +47,6 @@ void MainWindow::initializeBoundaries() pScene_->setSceneRect(rectangle); pView_->setSceneRect(rectangle); - pTursas_->setBoundaries(rectangle); - pTursas_->startMoving(); qDebug() << "Initialized boundaries" << rectangle.left() << rectangle.right() << pView_->width(); diff --git a/seascene.cpp b/seascene.cpp index 963317f..5c35e49 100644 --- a/seascene.cpp +++ b/seascene.cpp @@ -1,6 +1,9 @@ #include "seascene.h" +#include "timercontrolledtursas.h" +#include "orientationcontrolledgraphicspixmapobject.h" #include #include +#include const QString ghostImageFilename_ = ":/pix/aave.png"; const QString rockImageFilename_ =":/pix/kari.png"; @@ -34,9 +37,72 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses) freeTiles_.append(QPointF(i*40,j*40)); } } + + + //spread the rocks + + for (int i = 0; i < rocks; i++) + { + QPointF * pPosition = findRandomFreeSlot(); + + //If there was no room no point to continue + if (pPosition == NULL) + break; + + QGraphicsPixmapItem * pRock = addPixmap(QPixmap(":/pix/kari.png")); + pRock->setData(0,"rock"); + pRock->setPos(*pPosition); + delete pPosition; + + } + + //spread the ghosts + spreadGhosts(ghosts); + + + + //spread the octopuses + + + for (int i=0; i < octopuses; i++) + { + QPointF * pPosition = findRandomFreeSlot(); + + //If there was no room no point to continue + if (pPosition == NULL) + break; + + TimerControlledTursas * pOctopus = new TimerControlledTursas (QPixmap(":/pix/tursas.png"),100); + pOctopus->setData(0,"octopus"); + pOctopus->setPos(*pPosition); + addItem(pOctopus); + pOctopus->startMoving(); + delete pPosition; + + } + + + //place the ship + + QPointF * pPosition = findRandomFreeSlot(); + if (pPosition == NULL) + { + // Game cannot begin without a free position for ship, so give an error message and return + + QMessageBox::critical(NULL,"Error! Too many objects on screen","No free space to place the ship. The game cannot start. Please choose another level."); + return; + } + + OrientationControlledGraphicsPixmapObject * pShip = new OrientationControlledGraphicsPixmapObject(QPixmap(":/pix/laiva.png")); + pShip->setData(0,"ship"); + pShip->setPos(*pPosition); + addItem(pShip); + pShip->startMoving(); + delete pPosition; } + void SeaScene::spreadGhosts(int ghosts) { for (int i=0; i < ghosts; i++) diff --git a/seascene.h b/seascene.h index 9abc977..bb97911 100644 --- a/seascene.h +++ b/seascene.h @@ -13,6 +13,12 @@ signals: public slots: + /*! Places all needed items for a level to (re)start. + Relies on the scene size to be explicitly set to a a value that will persist troughout play. + @param ghosts the number of ghosts to be placed on the map + @param rocks the number of rocks to be placed on the map + @param octopuses number of octopuses to be placed on the map + */ void setupMap(int ghosts, int rocks, int octopuses); void spreadGhosts(int ghosts);