Multi-Scene-Multi-Level Demo
import Felgo 4.0
import QtQuick 2.0
import "../common"
SceneBase {
id:gameScene
property string activeLevelFileName
property variant activeLevel
property int score: 0
property int countdown: 0
property bool gameRunning: countdown == 0
function setLevel(fileName) {
activeLevelFileName = fileName
}
Rectangle {
anchors.fill: parent.gameWindowAnchorItem
color: "#dd94da"
}
MenuButton {
text: "Back to menu"
anchors.right: gameScene.gameWindowAnchorItem.right
anchors.rightMargin: 10
anchors.top: gameScene.gameWindowAnchorItem.top
anchors.topMargin: 10
onClicked: {
backButtonPressed()
activeLevel = undefined
activeLevelFileName = ""
}
}
Text {
anchors.left: gameScene.gameWindowAnchorItem.left
anchors.leftMargin: 10
anchors.top: gameScene.gameWindowAnchorItem.top
anchors.topMargin: 10
color: "white"
font.pixelSize: 20
text: activeLevel !== undefined ? activeLevel.levelName : ""
}
Loader {
id: loader
source: activeLevelFileName != "" ? "../levels/" + activeLevelFileName : ""
onLoaded: {
score = 0
item.width = gameScene.width
item.height = gameScene.height
activeLevel = item
countdown = 3
}
}
Connections {
target: activeLevel !== undefined ? activeLevel : null
function onRectanglePressed() {
if(gameRunning) {
score++
}
}
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: gameScene.gameWindowAnchorItem.top
anchors.topMargin: 30
color: "white"
font.pixelSize: 40
text: score
}
Text {
anchors.centerIn: parent
color: "white"
font.pixelSize: countdown > 0 ? 160 : 18
text: countdown > 0 ? countdown : "tap!"
}
Timer {
repeat: true
running: countdown > 0
onTriggered: {
countdown--