Keeps screen lit and pauses when app is backgrounded
[ghostsoverboard] / seascene.cpp
index 7a6a9db..4c2e72c 100644 (file)
@@ -14,6 +14,9 @@ const QString octopusImageFilename_= ":/pix/tursas.png";
 SeaScene::SeaScene(QObject *parent) :
     QGraphicsScene(parent)
 {
+    paused_ = false;
+    screenLitKeeper_.keepScreenLit(true);
+
     //set background
 
     QPixmap waves (":/pix/meri.png");
@@ -24,6 +27,8 @@ SeaScene::SeaScene(QObject *parent) :
 
     qsrand(QTime::currentTime().msec()+2);  //+2 to avoid setting it to 1
 
+
+
 }
 
 void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
@@ -101,6 +106,8 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
     addItem(pOctopus);
     pOctopus->startMoving();
     movingItems_.append(pOctopus);
+    connect(this,SIGNAL(pauseOn()),pOctopus,SLOT(stopMoving()));
+    connect(this,SIGNAL(pauseOff()),pOctopus,SLOT(startMoving()));
     delete pPosition;
 
     }
@@ -138,6 +145,8 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
     connect(pShip,SIGNAL(droppingGhosts(int)),this,SLOT(ghostsDropped(int)));
     pShip->startMoving();
     movingItems_.append(pShip);
+    connect(this,SIGNAL(pauseOn()),pShip,SLOT(stopMoving()));
+    connect(this,SIGNAL(pauseOff()),pShip,SLOT(startMoving()));
     delete pPosition;
 }
 
@@ -250,3 +259,26 @@ void SeaScene::ghostsDropped(int ghosts)
 
     spreadGhosts(ghosts);
 }
+
+void SeaScene::pause(bool paused)
+{
+    //    qDebug() << "pause pressed " << paused;
+        if (paused_ == paused)
+                return;
+
+        paused_ = paused;
+
+        if (paused == false)
+        {
+     //       qDebug() << "starting to move again";
+            emit pauseOff();
+            screenLitKeeper_.keepScreenLit(true);
+        }
+
+        else
+        {
+     //       qDebug("about to stop movement");
+            emit pauseOn();
+            screenLitKeeper_.keepScreenLit(false);
+        }
+}