ZombieBreak Demo
import Felgo 4.0
import QtQuick 2.0
import "entities"
Scene {
id: gameScene
property variant activeLevel
property string activeLevelString : "Level1"
property alias breakSound: breakSound
property int killedZombies: 0
state: "ready"
EntityManager {id:entityManager; entityContainer: gameScene}
PhysicsWorld {updatesPerSecondForPhysics:60}
Image {source:activeLevel.background; anchors.fill:parent}
GameSoundEffect {id:breakSound; source: Qt.resolvedUrl("../assets/snd/ow.wav") }
Wall {height:parent.height; anchors.right:parent.left}
Wall {height:parent.height; anchors.left:parent.right}
Wall {width:parent.width; anchors.bottom:parent.top}
Wall {
width: gameScene.width
anchors.top: parent.bottom
collision.onBeginContact: {
levelFailed()
}
}
HUD {
id: hud
width: gameScene.width
height: 30
cityText: "City: " + activeLevel.city
killedText: "Zombies killed: " + gameScene.killedZombies
}
Paddle {
id: paddle
width: 88
height: 34
x: parent.width/2 - width/2
y: parent.height - height
MouseArea {
id: paddleTouchArea
width: paddle.width*2
height: paddle.height*2
anchors.centerIn: paddle
drag.target: paddle
drag.axis: Drag.XAxis
drag.minimumX: 0
drag.maximumX: gameScene.width-paddle.width
enabled: gameScene.state === "ready" || gameScene.state === "running"
onPressed: {
if(gameScene.state === "ready")
startGame()
}
}
}
Bullet {
id: bullet
x: paddle.x + paddle.width/2
y: paddle.y - 5
}
Loader {
id: loader
source: activeLevelString + ".qml"
onLoaded: {
activeLevel = item
item.width = gameScene.width
item.height = gameScene.height/2
gameScene.killedZombies = 0
gameScene.state = "ready"
}
}
onKilledZombiesChanged: {
if(gameScene.killedZombies === activeLevel.maxZombies)
levelFinished()
}
SimpleButton {
id: nextCity
anchors.centerIn: parent;
text: "Next City"
visible: false
onClicked: {
nextCity.visible = false
gameScene.activeLevelString = "Level2"
loader.source = gameScene.activeLevelString + ".qml"
}
}
SimpleButton {
id: restartCity
anchors.centerIn: parent;
text: "Restart City"
visible: false
onClicked: {
restartCity.visible = false
loader.source = ""
loader.source = gameScene.activeLevelString + ".qml"
}
}
Text {
id: survived
color: "red"
text: "You survived!"
anchors.centerIn: parent;
visible: false
}
function startGame() {
bullet.reStart(width/2,height - 50)
state = "running"
}
function levelFinished() {
bullet.reset(width/2,height - 50)
state = "finished"
if(activeLevelString === "Level1")
nextCity.visible = true
else
survived.visible = true
}
function levelFailed() {
bullet.reset(width/2,height - 50)
state = "failed"