1 /**************************************************************************
2 Ghosts Overboard - a game for 'Meego 1.2 Harmattan'
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 **************************************************************************/
26 #include <QDBusMessage>
27 #include <QDBusConnection>
35 Ship::Ship(QList<QPixmap> pixmapList, QGraphicsItem *parent) :
36 OrientationControlledGraphicsPixmapObject(pixmapList.at(0),parent)
38 shipImages_ = pixmapList;
40 vibrationActive_ = false;
41 vibrationAllowed_ = false;
43 pVibrationEffect_ = new QFeedbackHapticsEffect();
44 pVibrationEffect_->setDuration(500);
45 pVibrationEffect_->setIntensity(1.0);
51 if (pVibrationEffect_)
52 delete pVibrationEffect_;
56 bool Ship::handleCollisions()
58 QList<QGraphicsItem*> collidesList = collidingItems();
60 if (collidesList.isEmpty())
65 //since the game logic does not leave items to collide with each other we can take just the topmost one
66 //and trust it is the only one
67 QString type = collidesList.at(0)->data(0).toString();
70 if (type == "rock" || type == "octopus")
72 // drop all ghosts when hitting an obstacle
76 //go back to old position
81 else if (type == "ghost")
86 // qDebug() << ghostsAboard_ << " ghosts aboard";
88 emit pickingGhost(collidesList.at(0));
96 return true; //execution can never reach here, this is just to stop the compiler from complaining
99 void Ship::updateShipImage()
101 int index = qBound(0,ghostsAboard_,shipImages_.length()-1);
102 setPixmap(shipImages_.at(index));
105 void Ship::dropAllGhosts()
108 emit droppingGhosts(ghostsAboard_);
114 if (vibrationActive_ && vibrationAllowed_)
117 // This is for fremantle
118 // QDBusMessage message = QDBusMessage::createMethodCall("com.nokia.mce","/com/nokia/mce/request","com.nokia.mce.request","req_vibrator_pattern_activate");
120 // QList<QVariant> arguments;
122 // arguments.append("PatternChatAndEmail");
124 // message.setArguments(arguments);
126 // message = QDBusConnection::systemBus().call(message);
128 //qDebug() << message;
131 //This is for Harmattan
133 pVibrationEffect_->start();
139 void Ship::setVibrationActivate(bool on)
141 vibrationActive_ = on;
144 void Ship::allowVibration()
146 vibrationAllowed_ = true;
149 void Ship::disallowVibration()
151 vibrationAllowed_ = false;