Also removed placing them from MainWindow.
QPixmap waves (":/pix/meri.png");
pScene_->setBackgroundBrush(QBrush(waves));
- pTursas_ = new OrientationControlledGraphicsPixmapObject(QPixmap(":/pix/laiva.png"));
- pScene_->addItem(pTursas_);
-
pView_->setScene(pScene_);
setCentralWidget(pView_);
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()
pScene_->setSceneRect(rectangle);
pView_->setSceneRect(rectangle);
- pTursas_->setBoundaries(rectangle);
- pTursas_->startMoving();
qDebug() << "Initialized boundaries" << rectangle.left() << rectangle.right() << pView_->width();
#include "seascene.h"
+#include "timercontrolledtursas.h"
+#include "orientationcontrolledgraphicspixmapobject.h"
#include <QGraphicsPixmapItem>
#include <QDebug>
+#include <QMessageBox>
const QString ghostImageFilename_ = ":/pix/aave.png";
const QString rockImageFilename_ =":/pix/kari.png";
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++)
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);