From fc5de9a3bac1a47d281a12a6f5a6e82c3c6c771b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Heli=20Hyv=C3=A4ttinen?= Date: Thu, 23 Jun 2011 22:14:25 +0300 Subject: [PATCH] Octopus speed given can now be zero or less If it is the octopus won't move. --- timercontrolledgraphicspixmapobject.cpp | 12 ++++++++++-- timercontrolledgraphicspixmapobject.h | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/timercontrolledgraphicspixmapobject.cpp b/timercontrolledgraphicspixmapobject.cpp index 56913f6..c9896c1 100644 --- a/timercontrolledgraphicspixmapobject.cpp +++ b/timercontrolledgraphicspixmapobject.cpp @@ -35,7 +35,8 @@ TimerControlledGraphicsPixmapObject::TimerControlledGraphicsPixmapObject(QPixmap void TimerControlledGraphicsPixmapObject::startMoving() { - timer_.start(); + if (!stoppedBecauseInvalidTime_) + timer_.start(); } void TimerControlledGraphicsPixmapObject::stopMoving() @@ -45,9 +46,16 @@ 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; } + void TimerControlledGraphicsPixmapObject::move() { diff --git a/timercontrolledgraphicspixmapobject.h b/timercontrolledgraphicspixmapobject.h index f121bf1..b4919fb 100644 --- a/timercontrolledgraphicspixmapobject.h +++ b/timercontrolledgraphicspixmapobject.h @@ -63,6 +63,8 @@ public slots: direction direction_; + bool stoppedBecauseInvalidTime_; + }; -- 1.7.9.5