From 0493211fef444777dca7855c0346c914fae47667 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Heli=20Hyv=C3=A4ttinen?= Date: Tue, 21 Jun 2011 10:41:55 +0300 Subject: [PATCH] Qctopuses now drop the ghosts when hitting the ship --- seascene.cpp | 6 +++--- ship.cpp | 15 +++++++++++---- timercontrolledgraphicspixmapobject.h | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/seascene.cpp b/seascene.cpp index 2986f2d..71304d0 100644 --- a/seascene.cpp +++ b/seascene.cpp @@ -88,7 +88,7 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses) //spread the octopuses - QList octopuses; + QList octopusList; for (int i=0; i < octopuses; i++) { @@ -107,7 +107,7 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses) movingItems_.append(pOctopus); connect(this,SIGNAL(pauseOn()),pOctopus,SLOT(stopMoving())); connect(this,SIGNAL(pauseOff()),pOctopus,SLOT(startMoving())); - octopuses.append(pOctopus); + octopusList.append(pOctopus); delete pPosition; } @@ -147,7 +147,7 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses) movingItems_.append(pShip); connect(this,SIGNAL(pauseOn()),pShip,SLOT(stopMoving())); connect(this,SIGNAL(pauseOff()),pShip,SLOT(startMoving())); - foreach (Octopus* pOctopus, octopuses) + foreach (Octopus* pOctopus, octopusList) { connect(pOctopus,SIGNAL(droppingGhosts()),pShip,SLOT(dropAllGhosts())); } diff --git a/ship.cpp b/ship.cpp index 1e80194..040e776 100644 --- a/ship.cpp +++ b/ship.cpp @@ -26,9 +26,10 @@ bool Ship::handleCollisions() if (type == "rock" || type == "octopus") { // drop all ghosts when hitting an obstacle - emit droppingGhosts(ghostsAboard_); - ghostsAboard_ = 0; - updateShipImage(); + + dropAllGhosts(); + + //go back to old position return false; } @@ -46,6 +47,9 @@ bool Ship::handleCollisions() } } + + + return true; //execution can never reach here, this is just to stop the compiler from complaining } void Ship::updateShipImage() @@ -56,6 +60,9 @@ void Ship::updateShipImage() void Ship::dropAllGhosts() { -//TODO + + emit droppingGhosts(ghostsAboard_); + ghostsAboard_ = 0; + updateShipImage(); } diff --git a/timercontrolledgraphicspixmapobject.h b/timercontrolledgraphicspixmapobject.h index da179f7..0e7a426 100644 --- a/timercontrolledgraphicspixmapobject.h +++ b/timercontrolledgraphicspixmapobject.h @@ -5,7 +5,7 @@ #include #include -class TimerControlledGraphisPixmapObject : public QObject, public QGraphicsPixmapItem +class TimerControlledGraphicsPixmapObject : public QObject, public QGraphicsPixmapItem { Q_OBJECT public: -- 1.7.9.5