diff options
Diffstat (limited to 'demos/declarative/snake')
-rw-r--r-- | demos/declarative/snake/content/Link.qml | 7 | ||||
-rw-r--r-- | demos/declarative/snake/content/snake.js | 16 | ||||
-rw-r--r-- | demos/declarative/snake/snake.qml | 41 |
3 files changed, 46 insertions, 18 deletions
diff --git a/demos/declarative/snake/content/Link.qml b/demos/declarative/snake/content/Link.qml index edaeeed..ff67ad7 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 5c089de..837b82a 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 (activeGame) { endGame(); startNewGameTimer.running = true; - state = ""; return; } diff --git a/demos/declarative/snake/snake.qml b/demos/declarative/snake/snake.qml index b7476b7..edccd4c 100644 --- a/demos/declarative/snake/snake.qml +++ b/demos/declarative/snake/snake.qml @@ -88,7 +88,7 @@ Rectangle { onTriggered: { Logic.moveSkull() } } Timer { - id: startNewGameTimer; + id: startNewGameTimer; interval: 700; onTriggered: { Logic.startNewGame(); } } @@ -109,6 +109,7 @@ Rectangle { } Image { + Image { id: title source: "content/pics/snake.jpg" @@ -117,14 +118,28 @@ Rectangle { anchors.horizontalCenter: parent.horizontalCenter anchors.verticalCenter: parent.verticalCenter - Text { - color: "white" - font.pointSize: 24 - horizontalAlignment: Text.AlignHCenter - text: "Last Score:\t" + lastScore + "\nHighscore:\t" + highScores.topScore; - anchors.horizontalCenter: parent.horizontalCenter - anchors.bottom: parent.bottom - anchors.bottomMargin: gridSize + Column { + spacing: 140 + anchors.verticalCenter: parent.verticalCenter; + anchors.left: parent.left; + anchors.right: parent.right; + + Text { + color: "white" + font.pointSize: 48 + font.italic: true; + font.bold: true; + text: "Snake" + anchors.horizontalCenter: parent.horizontalCenter; + } + + Text { + color: "white" + font.pointSize: 24 + anchors.horizontalCenter: parent.horizontalCenter; + //horizontalAlignment: Text.AlignHCenter + text: "Last Score:\t" + lastScore + "\nHighscore:\t" + highScores.topScore; + } } } @@ -154,7 +169,7 @@ Rectangle { MouseArea { anchors.fill: parent onPressed: { - if (!head || !heartbeat.running) { + if (screen.state == "") { Logic.startNewGame(); return; } @@ -245,10 +260,12 @@ Rectangle { from: "*" to: "starting" NumberAnimation { target: progressIndicator; property: "width"; duration: 1000 } - NumberAnimation { target: title; property: "opacity"; duration: 500 } + NumberAnimation { property: "opacity"; duration: 200 } }, Transition { - NumberAnimation { target: title; property: "opacity"; duration: 500 } + to: "starting" + NumberAnimation { target: progressIndicator; property: "width"; duration: 1000 } + NumberAnimation { property: "opacity"; duration: 200 } } ] |