Compiles again
[ghostsoverboard] / ship.cpp
1 /**************************************************************************
2         Ghosts Overboard - a game for 'Meego 1.2 Harmattan'
3
4         Copyright (C) 2011  Heli Hyvättinen
5
6         This file is part of Ghosts Overboard
7
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.
12
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.
17
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/>.
20
21 **************************************************************************/
22
23
24 #include "ship.h"
25 #include <QDebug>
26 #include <QDBusMessage>
27 #include <QDBusConnection>
28 #include <QFeedbackHapticsEffect>
29
30
31
32 QTM_USE_NAMESPACE
33
34
35 Ship::Ship(QList<QPixmap> pixmapList, QGraphicsItem *parent) :
36     OrientationControlledGraphicsPixmapObject(pixmapList.at(0),parent)
37 {
38     shipImages_ = pixmapList;
39     ghostsAboard_ = 0;
40     vibrationActive_ = false;
41 }
42
43 bool Ship::handleCollisions()
44 {
45     QList<QGraphicsItem*>  collidesList = collidingItems();
46
47     if (collidesList.isEmpty())
48         return true;
49
50     else
51     {
52         //since the game logic does not leave items to collide with each other we can take just the topmost one
53         //and trust it is the only one
54         QString type = collidesList.at(0)->data(0).toString();
55 //        qDebug() << type;
56
57         if (type == "rock" || type == "octopus")
58         {
59             // drop all ghosts when hitting an obstacle
60
61             dropAllGhosts();
62
63             //go back to old position
64
65             return false;
66         }
67
68         else if (type == "ghost")
69         {
70             ghostsAboard_++;
71             updateShipImage();
72
73 //            qDebug() << ghostsAboard_ << " ghosts aboard";
74
75             emit pickingGhost(collidesList.at(0));
76
77             return true;
78         }
79
80     }
81
82
83     return true; //execution can never reach here, this is just to stop the compiler from complaining
84 }
85
86 void Ship::updateShipImage()
87 {
88     int index = qBound(0,ghostsAboard_,shipImages_.length()-1);
89     setPixmap(shipImages_.at(index));
90 }
91
92 void Ship::dropAllGhosts()
93 {
94
95     emit droppingGhosts(ghostsAboard_);
96     ghostsAboard_ = 0;
97     updateShipImage();
98
99     //vibrate
100
101     if (vibrationActive_)
102     {
103
104  //       This is for fremantle
105 //        QDBusMessage message = QDBusMessage::createMethodCall("com.nokia.mce","/com/nokia/mce/request","com.nokia.mce.request","req_vibrator_pattern_activate");
106
107 //        QList<QVariant> arguments;
108
109 //        arguments.append("PatternChatAndEmail");
110
111 //        message.setArguments(arguments);
112
113 //        message = QDBusConnection::systemBus().call(message);
114
115     //qDebug() << message;
116
117
118         //This is for Harmattan
119
120         QFeedbackHapticsEffect vibrationEffect;
121         vibrationEffect.setDuration(1000);
122         vibrationEffect.setIntensity(1.0);
123         vibrationEffect.start();
124
125     }
126 }
127
128 void Ship::setVibrationActivate(bool on)
129 {
130     vibrationActive_ = on;
131 }