BalloonPop Demo
import Felgo 4.0
import QtQuick 2.0
import "entities"
Scene {
id: balloonScene
property alias popSound: popSound
property int balloons: 0
property int balloonsMax : 100
property int time : 20
property bool gameRunning: false
sceneAlignmentY: "top"
EntityManager {
id: entityManager
entityContainer: balloonScene
}
PhysicsWorld { gravity.y: -1; debugDrawVisible: false }
Image {source:"../assets/img/clouds.png"; anchors.fill:gameWindowAnchorItem; fillMode: Image.PreserveAspectCrop}
GameSoundEffect {id:popSound; source:Qt.resolvedUrl("../assets/snd/balloonPop.wav")}
Wall {height:gameWindowAnchorItem.height+50; anchors.right:gameWindowAnchorItem.left}
Wall {height:gameWindowAnchorItem.height+50; anchors.left:gameWindowAnchorItem.right}
Wall {width:gameWindowAnchorItem.width; anchors { bottom:gameWindowAnchorItem.top; left: gameWindowAnchorItem.left} }
Row {
anchors.bottom: gameWindowAnchorItem.bottom
z: 2
Text {id:infoText; width:200; height:40; text:"Loading balloons..."}
Text {id:timeText; height:40; text:"Time: "+balloonScene.time}
}
function start() {
spawnBaloons.start()
}
function reset() {
entityManager.removeEntitiesByFilter(["balloon"])
balloons = 0
time = 20
infoText.text = "Loading balloons..."
}
Timer {
id: spawnBaloons
interval: 20
repeat: true
onTriggered: {
entityManager.createEntityFromUrl(Qt.resolvedUrl("entities/Balloon.qml"));
balloons++
if(balloons===balloonsMax) {
running = false
gameRunning = true
infoText.text = "Hurry!"
}
}
}
Timer {
id: gameTimer
running: gameRunning
repeat: true
onTriggered: {
time--
if(time === 0 || balloons === 0) {
gameRunning = false
if(balloons === 0) infoText.text = "Perfect, take a cookie!"
else if(balloons < balloonsMax/2) infoText.text = "Well, that was decent..."
else infoText.text = "Not your day huh..."
restartAfterDelay.start()
}
}
}
Timer {
id: restartAfterDelay
interval: 4000
onTriggered: {
balloonScene.reset()
balloonScene.start()