demos/declarative/snake/snake.qml
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
    92     }
    92     }
    93 
    93 
    94     Timer {
    94     Timer {
    95         id: startHeartbeatTimer;
    95         id: startHeartbeatTimer;
    96         interval: 1000 ;
    96         interval: 1000 ;
       
    97         onTriggered: { state = "running"; heartbeat.running = true; }
    97     }
    98     }
    98 
    99 
    99 
   100 
   100     Image {
   101     Image {
   101         Image {
   102         Image {
   103             source: "content/pics/snake.jpg"
   104             source: "content/pics/snake.jpg"
   104             fillMode: Image.PreserveAspectCrop
   105             fillMode: Image.PreserveAspectCrop
   105             anchors.fill: parent
   106             anchors.fill: parent
   106             anchors.horizontalCenter: parent.horizontalCenter
   107             anchors.horizontalCenter: parent.horizontalCenter
   107             anchors.verticalCenter: parent.verticalCenter
   108             anchors.verticalCenter: parent.verticalCenter
   108             Behavior on opacity { NumberAnimation { duration: 500 } }
       
   109 
   109 
   110             Text {
   110             Text {
   111                 color: "white"
   111                 color: "white"
   112                 font.pointSize: 24
   112                 font.pointSize: 24
   113                 horizontalAlignment: Text.AlignHCenter
   113                 horizontalAlignment: Text.AlignHCenter
   191             id: btnA; text: "New Game"; onClicked: Logic.startNewGame();
   191             id: btnA; text: "New Game"; onClicked: Logic.startNewGame();
   192             anchors.left: parent.left; anchors.leftMargin: 3
   192             anchors.left: parent.left; anchors.leftMargin: 3
   193             anchors.verticalCenter: parent.verticalCenter
   193             anchors.verticalCenter: parent.verticalCenter
   194         }
   194         }
   195 
   195 
       
   196         Content.Button {
       
   197             text: "Quit"
       
   198             anchors { left: btnA.right; leftMargin: 3; verticalCenter: parent.verticalCenter }
       
   199             onClicked: Qt.quit();
       
   200         }
       
   201 
   196         Text {
   202         Text {
   197             color: activePalette.text
   203             color: activePalette.text
   198             text: "Score: " + score; font.bold: true
   204             text: "Score: " + score; font.bold: true
   199             anchors.right: parent.right; anchors.rightMargin: 3
   205             anchors.right: parent.right; anchors.rightMargin: 3
   200             anchors.verticalCenter: parent.verticalCenter
   206             anchors.verticalCenter: parent.verticalCenter
   209     Keys.onDownPressed: if (state == "starting" || direction != 0) Logic.scheduleDirection(2);
   215     Keys.onDownPressed: if (state == "starting" || direction != 0) Logic.scheduleDirection(2);
   210 
   216 
   211     states: [
   217     states: [
   212         State {
   218         State {
   213             name: "starting"
   219             name: "starting"
   214             when: startHeartbeatTimer.running
       
   215             PropertyChanges {target: progressIndicator; width: 200}
   220             PropertyChanges {target: progressIndicator; width: 200}
   216             PropertyChanges {target: title; opacity: 0}
   221             PropertyChanges {target: title; opacity: 0}
   217             PropertyChanges {target: progressBar; opacity: 1}
   222             PropertyChanges {target: progressBar; opacity: 1}
   218         },
   223         },
   219         State {
   224         State {
   220             name: "running"
   225             name: "running"
   221             when: (heartbeat.running && !startHeartbeatTimer.running)
       
   222             PropertyChanges {target: progressIndicator; width: 200}
   226             PropertyChanges {target: progressIndicator; width: 200}
   223             PropertyChanges {target: title; opacity: 0}
   227             PropertyChanges {target: title; opacity: 0}
   224             PropertyChanges {target: skull; row: 0; column: 0; }
   228             PropertyChanges {target: skull; row: 0; column: 0; }
   225             PropertyChanges {target: skull; spawned: 1}
   229             PropertyChanges {target: skull; spawned: 1}
   226         }
   230         }
   229     transitions: [
   233     transitions: [
   230         Transition {
   234         Transition {
   231             from: "*"
   235             from: "*"
   232             to: "starting"
   236             to: "starting"
   233             NumberAnimation { target: progressIndicator; property: "width"; duration: 1000 }
   237             NumberAnimation { target: progressIndicator; property: "width"; duration: 1000 }
   234 
   238             NumberAnimation { target: title; property: "opacity"; duration: 500 }
       
   239         },
       
   240         Transition {
       
   241             NumberAnimation { target: title; property: "opacity"; duration: 500 }
   235         }
   242         }
   236     ]
   243     ]
   237 
   244 
   238 }
   245 }