summaryrefslogtreecommitdiffstats
path: root/demos/declarative/snake/content
diff options
context:
space:
mode:
authormae <qt-info@nokia.com>2010-09-09 12:57:54 (GMT)
committermae <qt-info@nokia.com>2010-09-09 12:59:00 (GMT)
commita51c4ec60618ba575cb20e94bb019306074f432e (patch)
treea2b645e9b1ea2efca37ccc2b406ffbd7d5276018 /demos/declarative/snake/content
parent48b5fa29f5da3c241bc64520bd56ccd5713c4586 (diff)
downloadQt-a51c4ec60618ba575cb20e94bb019306074f432e.zip
Qt-a51c4ec60618ba575cb20e94bb019306074f432e.tar.gz
Qt-a51c4ec60618ba575cb20e94bb019306074f432e.tar.bz2
State handling cleanup
The game could end up in funky states when restarting while the startup animation was running. Also some smaller fixes for rotation.
Diffstat (limited to 'demos/declarative/snake/content')
-rw-r--r--demos/declarative/snake/content/Link.qml7
-rw-r--r--demos/declarative/snake/content/snake.js16
2 files changed, 17 insertions, 6 deletions
diff --git a/demos/declarative/snake/content/Link.qml b/demos/declarative/snake/content/Link.qml
index 9aa6006..d5c5773 100644
--- a/demos/declarative/snake/content/Link.qml
+++ b/demos/declarative/snake/content/Link.qml
@@ -77,7 +77,12 @@ Item { id:link
id: actualImageRotation
origin.x: width/2; origin.y: height/2;
angle: rotation * 90
- Behavior on angle { NumberAnimation { duration: spawned ? 200 : 0} }
+ Behavior on angle {
+ RotationAnimation{
+ direction: RotationAnimation.Shortest
+ duration: spawned ? 200 : 0
+ }
+ }
}
}
diff --git a/demos/declarative/snake/content/snake.js b/demos/declarative/snake/content/snake.js
index fab7834..2a99aa8 100644
--- a/demos/declarative/snake/content/snake.js
+++ b/demos/declarative/snake/content/snake.js
@@ -22,20 +22,26 @@ function rand(n)
function scheduleDirection(dir)
{
- direction = dir;
- if(scheduledDirections[scheduledDirections.length-1]!=direction)
- scheduledDirections.push(direction);
+ if (state == "starting") {
+ direction = dir;
+ headDirection = direction;
+ head.rotation = headDirection;
+ } else if (state == "running"){
+ direction = dir;
+ if(scheduledDirections[scheduledDirections.length-1]!=direction)
+ scheduledDirections.push(direction);
+ }
}
function startNewGame()
{
- if (state == "starting")
+ if (state == "starting") {
return;
+ }
if (heartbeat.running) {
endGame();
startNewGameTimer.running = true;
- state = "starting";
return;
}