//spread the ghosts
+ ghostsLeft_ = ghosts;
spreadGhosts(ghosts);
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;
}
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);
}
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.
QList<QPointF> freeTiles_;
+ int ghostsLeft_;
+
if (type == "rock" || type == "octopus")
{
-// dropGhosts();
+ // drop all ghosts when hitting an obstacle
+ emit droppingGhosts(ghostsAboard_);
+ ghostsAboard_ = 0;
+
return false;
}
/*! Emitted when a ghost is hit */
void pickingGhost(QGraphicsItem* pGhost);
+ /*! Emitted when ghosts fall over board */
+ void droppingGhosts (int ghosts);
+
public slots:
protected: