qsrand(QTime::currentTime().msec()+2); //+2 to avoid setting it to 1
+ //connect selecting to menu handling (only menu items selectable)
+
+ connect(this,SIGNAL(selectionChanged()),this,SLOT(menuClicked()));
+
+
+
+
+
+
+
}
-void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
+void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed)
{
//empty the map
clear();
+ createMenuItems();
+
//empty the list of moving items
movingItems_.clear();
break;
QPixmap octopusPixmap (":/pix/tursas.png");
- Octopus * pOctopus = new Octopus(octopusPixmap,100);
+ Octopus * pOctopus = new Octopus(octopusPixmap,octopusSpeed);
pOctopus->setData(0,"octopus");
pOctopus->setPos(*pPosition);
addItem(pOctopus);
addItem(pShip);
connect(pShip,SIGNAL(pickingGhost(QGraphicsItem*)),this, SLOT(removeGhost(QGraphicsItem*)) );
connect(pShip,SIGNAL(droppingGhosts(int)),this,SLOT(ghostsDropped(int)));
+ connect(this,SIGNAL(vibrationActivated(bool)),pShip,SLOT(setVibrationActivate(bool)));
pShip->startMoving();
movingItems_.append(pShip);
connect(this,SIGNAL(pauseOn()),pShip,SLOT(stopMoving()));
delete pPosition;
}
+void SeaScene::setupMap(Level level)
+{
+ setupMap(level.getNumberOfGhosts(),level.getNumberOfRocks(),level.getNumberOfOctopuses(),level.getOctopusSpeed());
+}
void SeaScene::spreadGhosts(int ghosts)
{
// qDebug() << "starting to move again";
emit pauseOff();
screenLitKeeper_.keepScreenLit(true);
+ if (pPausetextItem_)
+ pPausetextItem_->hide();
}
else
{
- // qDebug("about to stop movement");
+ qDebug("about to stop movement");
emit pauseOn();
screenLitKeeper_.keepScreenLit(false);
+ if (pPausetextItem_ != NULL)
+ {
+ qDebug() << "about to show the pause text";
+ pPausetextItem_->show();
+ qDebug() << "showing pause text";
+ }
+ else qDebug() << "No pause text available";
}
}
+
+void SeaScene::vibrationActivate(bool on)
+{
+ emit vibrationActivated(on);
+}
+
+void SeaScene::menuClicked()
+{
+ QList<QGraphicsItem *> items = selectedItems();
+
+ //if nothing selected (selection was removed) do nothing
+
+ if (items.isEmpty())
+ return;
+
+ //Tapping the screen unpaused the game, pause it again!
+
+
+
+ //Menu functions
+
+ QGraphicsItem* pItem = items.at(0);
+
+
+ if (pItem == pRestartGameItem_)
+ {
+ qDebug() << "game restart requested";
+ }
+
+ else if (pItem == pRestartLevelItem_)
+ {
+ qDebug() << "Level restart requested";
+
+ }
+
+ else if (pItem == pSettingsItem_)
+ {
+
+ }
+
+ else if (pItem == pAboutItem_)
+ {
+
+ }
+
+
+ //Selection is just used to get notice of being clicked, removed after use
+
+ clearSelection();
+
+}
+
+
+
+void SeaScene::createMenuItems()
+{
+
+ pPausetextItem_ = addSimpleText("Game paused. Tap to continue.");
+ pPausetextItem_->setZValue(1000);
+ pPausetextItem_->setPos(250,50);
+ pPausetextItem_->hide();
+
+ menuItemCount_ = 0;
+
+ pRestartGameItem_ = new QGraphicsSimpleTextItem("Restart game");
+ prepareForMenu(pRestartGameItem_);
+
+ pRestartLevelItem_ = new QGraphicsSimpleTextItem("Restart level");
+ prepareForMenu(pRestartLevelItem_);
+
+ pSettingsItem_ = new QGraphicsSimpleTextItem("Settings");
+ prepareForMenu(pSettingsItem_);
+
+ pAboutItem_ = new QGraphicsSimpleTextItem("About");
+ prepareForMenu(pAboutItem_);
+
+}
+
+void SeaScene::prepareForMenu(QGraphicsItem * pItem)
+{
+
+ //Menu items have pause text item as their parent and are thus added to scene automatically
+ //They are also shown and hidden with it, resulting in the menu being visble when the game is paused
+ //Their coordinates are given relative to the parent.
+
+ pItem->setParentItem(pPausetextItem_);
+ pItem->setZValue(1000);
+ pItem->setFlag(QGraphicsItem::ItemIsSelectable);
+ pItem->setY(150);
+ pItem->setX(menuItemCount_++*150-250);
+ }
+