Octopuses no longer need fixed pixmap size
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 21 Jun 2011 07:53:05 +0000 (10:53 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Tue, 21 Jun 2011 07:53:05 +0000 (10:53 +0300)
Also removed obsolete Timercontrolletursas class

ghostsoverboard.pro
timercontrolledgraphicspixmapobject.cpp
timercontrolledtursas.cpp [deleted file]
timercontrolledtursas.h [deleted file]

index f847c88..58faafd 100644 (file)
@@ -13,7 +13,6 @@ TEMPLATE = app
 SOURCES += main.cpp\
         mainwindow.cpp \
     orientationcontrolledgraphicspixmapobject.cpp \
-    timercontrolledtursas.cpp \
     seascene.cpp \
     seaview.cpp \
     ship.cpp \
@@ -23,7 +22,6 @@ SOURCES += main.cpp\
 
 HEADERS  += mainwindow.h \
     orientationcontrolledgraphicspixmapobject.h \
-    timercontrolledtursas.h \
     seascene.h \
     seaview.h \
     ship.h \
index e6b838c..e2573fb 100644 (file)
@@ -68,14 +68,14 @@ void TimerControlledGraphicsPixmapObject::move()
 
     QRect sceneRectangle = scene()->sceneRect().toRect();
 
-    if (newx < sceneRectangle.left() || newx > sceneRectangle.right()-40)
+    if (newx < sceneRectangle.left() || newx > sceneRectangle.right()-pixmap().width())
     {
         changeDirection();
         return;
     }
 
 
-    if (newy < sceneRectangle.top() || newy > sceneRectangle.bottom()-40)
+    if (newy < sceneRectangle.top() || newy > sceneRectangle.bottom()-pixmap().height())
     {
         changeDirection();
         return;     //the old x and y values remain intact
@@ -102,10 +102,10 @@ void TimerControlledGraphicsPixmapObject::move()
 
 void TimerControlledGraphicsPixmapObject::changeDirection()
 {
-    qDebug () << "Supposed to change direction";
+ //   qDebug () << "Supposed to change direction";
 
     int direction = (qrand()%8);
-    qDebug()  << direction;
+ //   qDebug()  << direction;
 
     switch (direction)
     {
diff --git a/timercontrolledtursas.cpp b/timercontrolledtursas.cpp
deleted file mode 100644 (file)
index 07828ff..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-#include "timercontrolledtursas.h"
-#include <QGraphicsScene>
-#include <QDebug>
-
-
-TimerControlledTursas::TimerControlledTursas(QPixmap pixmap, int speed, QGraphicsItem* parent) :
-    QObject(), QGraphicsPixmapItem(pixmap, parent)
-{
-    setSpeed(speed);
-    direction_ = S;
-    connect(&timer_,SIGNAL(timeout()),this,SLOT(move()));
-}
-
-void TimerControlledTursas::startMoving()
-{
-    timer_.start();
-}
-
-void TimerControlledTursas::stopMoving()
-{
-    timer_.stop();
-}
-
-void TimerControlledTursas::setSpeed(int speed)
-{
-    timer_.setInterval(1000/speed); //converts from pixels in second to milliseconds per pixel
-}
-
-void TimerControlledTursas::move()
-{
-
-    int oldx = x();
-    int oldy = y();
-
-    int newx = oldx;
-    int newy = oldy;
-
-
-    //calculate the new position
-
-    if (direction_ == E || direction_ == SE || direction_ == NE)
-    {
-        newx++;
-    }
-
-    if (direction_ == W || direction_ == SW || direction_ == NW)
-    {
-        newx--;
-    }
-
-    if (direction_ == S || direction_ == SE || direction_ == SW)
-    {
-        newy++;
-    }
-
-    if (direction_ == N || direction_ == NE || direction_ == NW)
-    {
-        newy--;
-    }
-
-
-
-    //Bound the item into the scene and change direction if hitting a boundary
-    //Only works if the old position is inside the boundaries
-
-    if (!scene()) //no movement if this item does not belong to a scene
-        return;
-
-    QRect sceneRectangle = scene()->sceneRect().toRect();
-
-    if (newx < sceneRectangle.left() || newx > sceneRectangle.right()-40)
-    {
-        changeDirection();
-        return;
-    }
-
-
-    if (newy < sceneRectangle.top() || newy > sceneRectangle.bottom()-40)
-    {
-        changeDirection();
-        return;     //the old x and y values remain intact
-    }
-
-
-    //Set the new position
-
-    setX(newx);
-    setY(newy);
-
-
-    //If the new position would collide with anything, go back to the old position and change direction
-
-    QList<QGraphicsItem*>  collidesList = collidingItems();
-    if (!collidesList.isEmpty())
-    {
-        setX(oldx);
-        setY(oldy);
-        changeDirection();
-    }
-
-
-}
-
-void TimerControlledTursas::changeDirection()
-{
-    qDebug () << "Supposed to change direction";
-
-    int direction = (qrand()%8);
-    qDebug()  << direction;
-
-    switch (direction)
-    {
-        case 0:
-            direction_ = S;
-            break;
-
-        case 1:
-            direction_ = SW;
-            break;
-
-       case 2:
-            direction_ = W;
-            break;
-
-       case 3:
-            direction_ = NW;
-            break;
-
-       case 4:
-            direction_ = N;
-            break;
-
-       case 5:
-            direction_ = NE;
-            break;
-
-       case 6:
-            direction_ = E;
-            break;
-
-      case 7:
-            direction_ = SE;
-            break;
-
-
-    }
-
-}
-
diff --git a/timercontrolledtursas.h b/timercontrolledtursas.h
deleted file mode 100644 (file)
index 12316b1..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-#ifndef TIMERCONTROLLEDTURSAS_H
-#define TIMERCONTROLLEDTURSAS_H
-
-#include <QObject>
-#include <QGraphicsPixmapItem>
-#include <QTimer>
-
-class TimerControlledTursas : public QObject, public QGraphicsPixmapItem
-{
-    Q_OBJECT
-public:
-    explicit TimerControlledTursas(QPixmap pixmap = QPixmap(), int speed = 1, QGraphicsItem *parent = 0);
-
-
-signals:
-
-public slots:
-
-    void startMoving();
-    void stopMoving();
-
-    /*! Intended to be used internally by connecting to a timer
-      */
-    void move();
-
-    /*! Sets the movement speed of the item
-      @param speed given in pixels per second
-      */
-    void setSpeed(int speed);
-
-
- protected:
-
-    void changeDirection();
-
-    QTimer timer_;
-
-    enum direction {N, NE, E, SE, S, SW, W, NW};
-
-    direction direction_;
-
-};
-
-#endif // TIMERCONTROLLEDTURSAS_H