From 1443a50e20166afe1ce18e0e64a5a11fbbc3b7a8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Heli=20Hyv=C3=A4ttinen?= Date: Mon, 6 Jun 2011 20:46:08 +0300 Subject: [PATCH] The ship now drops all ghosts overboard when hitting an obstacle 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 | 15 +++++++++++++++ seascene.h | 4 ++++ ship.cpp | 5 ++++- ship.h | 3 +++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/seascene.cpp b/seascene.cpp index cfa78ec..50a0152 100644 --- a/seascene.cpp +++ b/seascene.cpp @@ -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); } diff --git a/seascene.h b/seascene.h index 1d0c1fc..5bea885 100644 --- a/seascene.h +++ b/seascene.h @@ -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 freeTiles_; + int ghostsLeft_; + diff --git a/ship.cpp b/ship.cpp index 2c26b45..4a516e7 100644 --- 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 --- 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: -- 1.7.9.5