Spread ghost should no longer be placed on top of the ship and octupuses
[ghostsoverboard] / ship.cpp
1 #include "ship.h"
2 #include <QDebug>
3
4 Ship::Ship(QPixmap pixmap, QGraphicsItem *parent) :
5     OrientationControlledGraphicsPixmapObject(pixmap,parent)
6 {
7     ghostsAboard_ = 0;
8
9 }
10
11 bool Ship::handleCollisions()
12 {
13     QList<QGraphicsItem*>  collidesList = collidingItems();
14
15     if (collidesList.isEmpty())
16         return true;
17
18     else
19     {
20         //since the game logic does not leave items to collide with each other we can take just the topmost one
21         //and trust it is the only one
22         QString type = collidesList.at(0)->data(0).toString();
23         qDebug() << type;
24
25         if (type == "rock" || type == "octopus")
26         {
27             // drop all ghosts when hitting an obstacle
28             emit droppingGhosts(ghostsAboard_);
29             ghostsAboard_ = 0;
30
31             return false;
32         }
33
34         else if (type == "ghost")
35         {
36             ghostsAboard_++;
37
38             qDebug() << ghostsAboard_ << " ghosts aboard";
39
40             emit pickingGhost(collidesList.at(0));
41
42             return true;
43         }
44
45     }
46 }