Merge branch 'levelstructure'
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 5 Jul 2011 15:56:37 +0000 (18:56 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 5 Jul 2011 15:56:37 +0000 (18:56 +0300)
Conflicts:
mainwindow.cpp

Multiple levels now supported. 5 levels now.
"Restart game" added to the menu.

ghostsoverboard.pro
mainwindow.cpp
mainwindow.h
seascene.cpp
seascene.h
ship.cpp
ship.h
timercontrolledgraphicspixmapobject.cpp
timercontrolledgraphicspixmapobject.h

index 8f2cb91..4309de7 100644 (file)
@@ -5,6 +5,7 @@
 #-------------------------------------------------
 
 QT       += core gui
+QT      += dbus
 
 TARGET = ghostsoverboard
 TEMPLATE = app
index 0621f7d..0845aa7 100644 (file)
@@ -59,6 +59,12 @@ MainWindow::MainWindow(QWidget *parent)
     connect(pRestartLevelAction,SIGNAL(triggered()),this,SLOT(restartLevel()));
     menuBar()->addAction(pRestartLevelAction);
 
+    QAction * pVibrateAction = new QAction(tr("Vibration effects"),this);
+    pVibrateAction->setCheckable(true);
+    addAction(pVibrateAction);
+    connect(pVibrateAction,SIGNAL(triggered(bool)),pScene_,SLOT(vibrationActivate(bool)));
+    menuBar()->addAction(pVibrateAction);
+
 
     QAction * pAboutAction = new QAction(tr("About"),this);
     addAction(pAboutAction);
@@ -83,6 +89,7 @@ MainWindow::MainWindow(QWidget *parent)
 
     currentLevel_ = 0;
 
+
     //the boundaries of the scene are set to match the size of the view window, which is not
     //available in the constructor --> timer needed
     QTimer::singleShot(100,this,SLOT(initializeBoundaries()));
index 31438ed..91be672 100644 (file)
@@ -47,6 +47,7 @@ public slots:
     void restartGame();
 
 
+
 private:
 
 SeaScene * pScene_;
@@ -55,6 +56,7 @@ QAction* pPauseAction_;
 QList<Level> levelList_;
 int currentLevel_;
 
+
 };
 
 #endif // MAINWINDOW_H
index 2adbb8c..764fea9 100644 (file)
@@ -165,6 +165,7 @@ void SeaScene::setupMap(int ghosts, int rocks, int octopuses, int octopusSpeed)
     addItem(pShip);
     connect(pShip,SIGNAL(pickingGhost(QGraphicsItem*)),this, SLOT(removeGhost(QGraphicsItem*)) );
     connect(pShip,SIGNAL(droppingGhosts(int)),this,SLOT(ghostsDropped(int)));
+    connect(this,SIGNAL(vibrationActivated(bool)),pShip,SLOT(setVibrationActivate(bool)));
     pShip->startMoving();
     movingItems_.append(pShip);
     connect(this,SIGNAL(pauseOn()),pShip,SLOT(stopMoving()));
@@ -312,3 +313,8 @@ void SeaScene::pause(bool paused)
             screenLitKeeper_.keepScreenLit(false);
         }
 }
+
+void SeaScene::vibrationActivate(bool on)
+{
+    emit vibrationActivated(on);
+}
index db65f17..9fb0734 100644 (file)
@@ -16,6 +16,7 @@ signals:
     void allGhostsPicked();
     void pauseOn();
     void pauseOff();
+    void vibrationActivated(bool on);
 
 public slots:
 
@@ -37,6 +38,8 @@ public slots:
 
     void pause (bool paused);
 
+    void vibrationActivate(bool);
+
 protected:
 
     /*! Gives a pointer to a random position if a free one is found. Otherwise returns NULL.
index 426cd63..adcc202 100644 (file)
--- a/ship.cpp
+++ b/ship.cpp
 
 #include "ship.h"
 #include <QDebug>
+#include <QDBusMessage>
+#include <QDBusConnection>
+
 
 Ship::Ship(QList<QPixmap> pixmapList, QGraphicsItem *parent) :
     OrientationControlledGraphicsPixmapObject(pixmapList.at(0),parent)
 {
     shipImages_ = pixmapList;
     ghostsAboard_ = 0;
-
+    vibrationActive_ = false;
 }
 
 bool Ship::handleCollisions()
@@ -87,5 +90,26 @@ void Ship::dropAllGhosts()
     emit droppingGhosts(ghostsAboard_);
     ghostsAboard_ = 0;
     updateShipImage();
+
+    //vibrate
+
+    if (vibrationActive_)
+    {
+        QDBusMessage message = QDBusMessage::createMethodCall("com.nokia.mce","/com/nokia/mce/request","com.nokia.mce.request","req_vibrator_pattern_activate");
+
+        QList<QVariant> arguments;
+
+        arguments.append("PatternChatAndEmail");
+
+        message.setArguments(arguments);
+
+        message = QDBusConnection::systemBus().call(message);
+
+    //qDebug() << message;
+    }
 }
 
+void Ship::setVibrationActivate(bool on)
+{
+    vibrationActive_ = on;
+}
diff --git a/ship.h b/ship.h
index 3cb73de..f07bced 100644 (file)
--- a/ship.h
+++ b/ship.h
@@ -46,6 +46,8 @@ public slots:
 
     void dropAllGhosts();
 
+    void setVibrationActivate(bool on);
+
 protected:
 
 protected:
@@ -57,6 +59,8 @@ protected:
 
     QList<QPixmap> shipImages_;
 
+    bool vibrationActive_;
+
 
 };
 
index 56913f6..52fb616 100644 (file)
@@ -29,13 +29,14 @@ TimerControlledGraphicsPixmapObject::TimerControlledGraphicsPixmapObject(QPixmap
     QObject(), QGraphicsPixmapItem(pixmap, parent)
 {
     setSpeed(speed);
-    direction_ = S;
+    changeDirection();
     connect(&timer_,SIGNAL(timeout()),this,SLOT(move()));
 }
 
 void TimerControlledGraphicsPixmapObject::startMoving()
 {
-    timer_.start();
+    if (!stoppedBecauseInvalidTime_)
+        timer_.start();
 }
 
 void TimerControlledGraphicsPixmapObject::stopMoving()
@@ -45,9 +46,17 @@ void TimerControlledGraphicsPixmapObject::stopMoving()
 
 void TimerControlledGraphicsPixmapObject::setSpeed(int speed)
 {
-    timer_.setInterval(1000/speed); //converts from pixels in second to milliseconds per pixel
+    if (speed >0)
+    {
+        timer_.setInterval(1000/speed); //converts from pixels in second to milliseconds per pixel
+        stoppedBecauseInvalidTime_ = false;
+     }
+    else
+        stoppedBecauseInvalidTime_ = true;
+        timer_.stop();
 }
 
+
 void TimerControlledGraphicsPixmapObject::move()
 {
 
index f121bf1..b4919fb 100644 (file)
@@ -63,6 +63,8 @@ public slots:
 
     direction direction_;
 
+    bool stoppedBecauseInvalidTime_;
+
 
 };