Added copyright & licence info where missing
[ghostsoverboard] / orientationcontrolledgraphicspixmapobject.cpp
index 5b3b4b1..d86ea23 100644 (file)
@@ -1,3 +1,26 @@
+/**************************************************************************
+        Ghosts Overboard - a game for Maemo 5
+
+        Copyright (C) 2011  Heli Hyvättinen
+
+        This file is part of Ghosts Overboard
+
+        Ghosts Overboard is free software: you can redistribute it and/or modify
+        it under the terms of the GNU General Public License as published by
+        the Free Software Foundation, either version 2 of the License, or
+        (at your option) any later version.
+
+        This program is distributed in the hope that it will be useful,
+        but WITHOUT ANY WARRANTY; without even the implied warranty of
+        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+        GNU General Public License for more details.
+
+        You should have received a copy of the GNU General Public License
+        along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+**************************************************************************/
+
+
 #include "orientationcontrolledgraphicspixmapobject.h"
 #include <QDebug>
 #include <QGraphicsScene>
@@ -21,15 +44,15 @@ OrientationControlledGraphicsPixmapObject::OrientationControlledGraphicsPixmapOb
 void OrientationControlledGraphicsPixmapObject::startMoving()
 {
     rotationSensor_.start();
-    qDebug() << "started the sensor";
-    qDebug() << rotationSensor_.isActive();
+//    qDebug() << "started the sensor";
+//    qDebug() << rotationSensor_.isActive();
 }
 
 
 void OrientationControlledGraphicsPixmapObject::stopMoving()
 {
     rotationSensor_.stop();
-    qDebug () << "trying to stop the sensor";
+//    qDebug () << "trying to stop the sensor";
 }
 
 void OrientationControlledGraphicsPixmapObject::readRotationSensor()
@@ -48,6 +71,9 @@ void OrientationControlledGraphicsPixmapObject::readRotationSensor()
 
  //   qDebug() << deltax << " " << deltay;
 
+    int oldx = x();
+    int oldy = y();
+
     int newx = x() + deltax/15;
     int newy = y() + deltay/15;
 
@@ -58,14 +84,20 @@ void OrientationControlledGraphicsPixmapObject::readRotationSensor()
     setX(qBound(sceneRectangle.left(),newx,sceneRectangle.right()-pixmap().width()));
     setY(qBound(sceneRectangle.top(),newy,sceneRectangle.bottom()-pixmap().height()));
 
-}
 
+    //handle collisions and move back to the original position if false returned
 
-void OrientationControlledGraphicsPixmapObject::setBoundaries(QRectF boundaryrect)
-{
-    boundaryrect_ = boundaryrect;
+    if (handleCollisions() == false)
+    {
+        setX(oldx);
+        setY(oldy);
+    }
 
 }
 
 
+bool OrientationControlledGraphicsPixmapObject::handleCollisions()
+{
+    return true;
+}