1 /**************************************************************************
2 Ghosts Overboard - a game for Maemo 5
4 Copyright (C) 2011 Heli Hyvättinen
6 This file is part of Ghosts Overboard
8 Ghosts Overboard is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 **************************************************************************/
27 Ship::Ship(QList<QPixmap> pixmapList, QGraphicsItem *parent) :
28 OrientationControlledGraphicsPixmapObject(pixmapList.at(0),parent)
30 shipImages_ = pixmapList;
35 bool Ship::handleCollisions()
37 QList<QGraphicsItem*> collidesList = collidingItems();
39 if (collidesList.isEmpty())
44 //since the game logic does not leave items to collide with each other we can take just the topmost one
45 //and trust it is the only one
46 QString type = collidesList.at(0)->data(0).toString();
49 if (type == "rock" || type == "octopus")
51 // drop all ghosts when hitting an obstacle
55 //go back to old position
60 else if (type == "ghost")
65 // qDebug() << ghostsAboard_ << " ghosts aboard";
67 emit pickingGhost(collidesList.at(0));
75 return true; //execution can never reach here, this is just to stop the compiler from complaining
78 void Ship::updateShipImage()
80 int index = qBound(0,ghostsAboard_,shipImages_.length()-1);
81 setPixmap(shipImages_.at(index));
84 void Ship::dropAllGhosts()
87 emit droppingGhosts(ghostsAboard_);