pShip->setData(0,"ship");
pShip->setPos(*pPosition);
addItem(pShip);
+ connect(pShip,SIGNAL(pickingGhost(QGraphicsItem*)),this, SLOT(removeGhost(QGraphicsItem*)) );
pShip->startMoving();
delete pPosition;
}
return new QPointF (freeTiles_.takeAt(index));
}
+
+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;
+}
void spreadGhosts(int ghosts);
+ void removeGhost(QGraphicsItem * pGhost);
+
protected:
/*! Gives a pointer to a random position if a free one is found. Otherwise returns NULL.
Ship::Ship(QPixmap pixmap, QGraphicsItem *parent) :
OrientationControlledGraphicsPixmapObject(pixmap,parent)
{
+ ghostsAboard_ = 0;
}
else
{
+ //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;
+
if (type == "rock" || type == "octopus")
{
// dropGhosts();
else if (type == "ghost")
{
+ ghostsAboard_++;
+
+ qDebug() << ghostsAboard_ << " ghosts aboard";
+
+ emit pickingGhost(collidesList.at(0));
+
return true;
}
signals:
+ /*! Emitted when a ghost is hit */
+ void pickingGhost(QGraphicsItem* pGhost);
+
public slots:
protected:
protected:
bool handleCollisions();
+ int ghostsAboard_;
+
};