Octopuses move 2 pixels at time
authorHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 10 Oct 2011 19:48:26 +0000 (22:48 +0300)
committerHeli Hyvättinen <heli.hyvattinen@kymp.net>
Mon, 10 Oct 2011 19:48:26 +0000 (22:48 +0300)
Allows faster speeds. (Timers more often than roughly 10 ms seem not to
be available on N950.)

timercontrolledgraphicspixmapobject.cpp
timercontrolledgraphicspixmapobject.h

index 52fb616..f577fd1 100644 (file)
@@ -28,6 +28,7 @@
 TimerControlledGraphicsPixmapObject::TimerControlledGraphicsPixmapObject(QPixmap pixmap, int speed, QGraphicsItem* parent) :
     QObject(), QGraphicsPixmapItem(pixmap, parent)
 {
+    pixelsPerMove_ = 2;
     setSpeed(speed);
     changeDirection();
     connect(&timer_,SIGNAL(timeout()),this,SLOT(move()));
@@ -48,7 +49,7 @@ void TimerControlledGraphicsPixmapObject::setSpeed(int speed)
 {
     if (speed >0)
     {
-        timer_.setInterval(1000/speed); //converts from pixels in second to milliseconds per pixel
+        timer_.setInterval((1000/(speed/pixelsPerMove_))); //converts from pixels in second to milliseconds per pixels moved at once
         stoppedBecauseInvalidTime_ = false;
      }
     else
@@ -71,22 +72,22 @@ void TimerControlledGraphicsPixmapObject::move()
 
     if (direction_ == E || direction_ == SE || direction_ == NE)
     {
-        newx++;
+        newx+= pixelsPerMove_;
     }
 
     if (direction_ == W || direction_ == SW || direction_ == NW)
     {
-        newx--;
+        newx-=pixelsPerMove_;
     }
 
     if (direction_ == S || direction_ == SE || direction_ == SW)
     {
-        newy++;
+        newy+=pixelsPerMove_;
     }
 
     if (direction_ == N || direction_ == NE || direction_ == NW)
     {
-        newy--;
+        newy-=pixelsPerMove_;
     }
 
 
index 09d1cd0..cdc401a 100644 (file)
@@ -65,6 +65,8 @@ public slots:
 
     bool stoppedBecauseInvalidTime_;
 
+    int pixelsPerMove_;
+
 
 };