#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;
}
//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));
}
}
+
+void Ship::updateShipImage()
+{
+ int index = qBound(0,ghostsAboard_,shipImages_.length()-1);
+ setPixmap(shipImages_.at(index));
+}