Octopuses now change direction
[ghostsoverboard] / ship.cpp
index 2c26b45..5c353d8 100644 (file)
--- a/ship.cpp
+++ b/ship.cpp
@@ -1,9 +1,10 @@
 #include "ship.h"
 #include <QDebug>
 
-Ship::Ship(QPixmap pixmap, QGraphicsItem *parent) :
-    OrientationControlledGraphicsPixmapObject(pixmap,parent)
+Ship::Ship(QList<QPixmap> pixmapList, QGraphicsItem *parent) :
+    OrientationControlledGraphicsPixmapObject(pixmapList.at(0),parent)
 {
+    shipImages_ = pixmapList;
     ghostsAboard_ = 0;
 
 }
@@ -20,19 +21,24 @@ bool Ship::handleCollisions()
         //since the game logic does not leave items to collide with each other we can take just the topmost one
         //and trust it is the only one
         QString type = collidesList.at(0)->data(0).toString();
-        qDebug() << type;
+//        qDebug() << type;
 
         if (type == "rock" || type == "octopus")
         {
-//            dropGhosts();
+            // drop all ghosts when hitting an obstacle
+            emit droppingGhosts(ghostsAboard_);
+            ghostsAboard_ = 0;
+            updateShipImage();
+
             return false;
         }
 
         else if (type == "ghost")
         {
             ghostsAboard_++;
+            updateShipImage();
 
-            qDebug() << ghostsAboard_ << " ghosts aboard";
+//            qDebug() << ghostsAboard_ << " ghosts aboard";
 
             emit pickingGhost(collidesList.at(0));
 
@@ -41,3 +47,9 @@ bool Ship::handleCollisions()
 
     }
 }
+
+void Ship::updateShipImage()
+{
+    int index = qBound(0,ghostsAboard_,shipImages_.length()-1);
+    setPixmap(shipImages_.at(index));
+}