The ship now drops all ghosts overboard when hitting an obstacle
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 6 Jun 2011 17:46:08 +0000 (20:46 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 6 Jun 2011 17:46:08 +0000 (20:46 +0300)
The placing of ghosts on the map does not take into account that
octopuses and the ship have moved to new positions (that do not respect
the tile system).

seascene.cpp
seascene.h
ship.cpp
ship.h

index cfa78ec..50a0152 100644 (file)
@@ -58,6 +58,7 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
 
     //spread the ghosts
 
+    ghostsLeft_ = ghosts;
     spreadGhosts(ghosts);
 
 
@@ -99,6 +100,7 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses)
     pShip->setPos(*pPosition);
     addItem(pShip);
     connect(pShip,SIGNAL(pickingGhost(QGraphicsItem*)),this, SLOT(removeGhost(QGraphicsItem*)) );
+    connect(pShip,SIGNAL(droppingGhosts(int)),this,SLOT(ghostsDropped(int)));
     pShip->startMoving();
     delete pPosition;
 }
@@ -138,4 +140,17 @@ void SeaScene::removeGhost(QGraphicsItem *pGhost)
     removeItem(pGhost);  //remove the item from scene
     freeTiles_.append(pGhost->scenePos()); //add the item's position to free slots
     delete pGhost;
+    ghostsLeft_--;
+    if (ghostsLeft_ == 0)
+    {
+        //here whatever happens when a level is complete / a signal
+        qDebug() << "All ghosts picked!";
+    }
+}
+
+void SeaScene::ghostsDropped(int ghosts)
+{
+    ghostsLeft_ += ghosts;
+
+    spreadGhosts(ghosts);
 }
index 1d0c1fc..5bea885 100644 (file)
@@ -25,6 +25,8 @@ public slots:
 
     void removeGhost(QGraphicsItem * pGhost);
 
+    void ghostsDropped(int ghosts);
+
 protected:
 
     /*! Gives a pointer to a random position if a free one is found. Otherwise returns NULL.
@@ -40,6 +42,8 @@ protected:
 
     QList<QPointF> freeTiles_;
 
+    int ghostsLeft_;
+
 
 
 
index 2c26b45..4a516e7 100644 (file)
--- a/ship.cpp
+++ b/ship.cpp
@@ -24,7 +24,10 @@ bool Ship::handleCollisions()
 
         if (type == "rock" || type == "octopus")
         {
-//            dropGhosts();
+            // drop all ghosts when hitting an obstacle
+            emit droppingGhosts(ghostsAboard_);
+            ghostsAboard_ = 0;
+
             return false;
         }
 
diff --git a/ship.h b/ship.h
index 42ec29a..62acfd1 100644 (file)
--- a/ship.h
+++ b/ship.h
@@ -14,6 +14,9 @@ signals:
     /*! Emitted when a ghost is hit */
     void  pickingGhost(QGraphicsItem* pGhost);
 
+    /*! Emitted when ghosts fall over board */
+    void droppingGhosts (int ghosts);
+
 public slots:
 
 protected: