ChickenOutbreak2 Demo
import QtQuick 2.0
import Felgo 4.0
import "entities"
SceneBase {
id: scene
property alias level: level
property alias player: level.player
property alias entityContainer: level
property string messageBox: ""
gridSize: 48
Connections {
target: window.activeScene === scene ? NativeUtils : null
function onMessageBoxFinished(accepted) {
audioManager.play(audioManager.idMENUCLICK)
console.debug("the user confirmed the Ok/Cancel dialog with:", accepted)
if(accepted && messageBox === "") {
level.stopGame();
window.state = "main"
} else {
messageBox = ""
level.resumeGame()
}
}
}
ParallaxScrollingBackground {
id: levelBackground
property int initialOffsetx: -(levelBackground.image.width-scene.width)/2
property int initialOffsety: -(levelBackground.image.height-scene.height)/2
x: initialOffsetx
y: initialOffsety
sourceImage: Qt.resolvedUrl("../assets/background-wood2.png")
movementVelocity: level.movementAnimation.velocity
running: level.movementAnimation.running
mirrorSecondImage: false
}
Level {
id: level
onGameLost: {
if(state !== "running")
return
player.prepareForDeath()
level.pauseGame()
if(!(system.desktopPlatform && system.publishBuild)) {
saveitDialog.setActive()
} else {
player.killIt()
}
}
PhysicsWorld {
id: physicsWorld
updatesPerSecondForPhysics: 60
gravity.y: level.gravity
velocityIterations: 4
positionIterations: 4
debugDrawVisible: false
}
}
Keys.forwardTo: player.controller
MultiPointTouchArea {
x: scene.gameWindowAnchorItem.x
y: scene.gameWindowAnchorItem.y+50
width: scene.gameWindowAnchorItem.width
height: scene.gameWindowAnchorItem.height-50
enabled: level.state === "running" || level.state === "teleporting"
property int startY
onPressed: {
startY = touchPoints[0].y
}
onReleased: {
console.debug("TOUCH RELEASED")
if(touchPoints[0].y > startY + 20) {
console.debug("onSwipeDown")
deactivateTeleport()
} else if(touchPoints[0].y < startY - 20) {
console.debug("onSwipeUp")
activateTeleport()
} else {
if(level.state === "running") player.startOrStopParachute()
else if(level.state === "teleporting") {
var mousePosition = mapToItem(level, touchPoints[0].x, touchPoints[0].y)
player.x = mousePosition.x - player.width/2
player.y = mousePosition.y - player.height/2
player.teleportParticle.start()
audioManager.play(audioManager.idTELEPORT)
}
}
}
}
function activateTeleport() {
if(teleportCount > 0 && level.state !== "teleporting") {
teleportCount--
level.toggleTeleport()
audioManager.play(audioManager.idSLOWMO)
player.teleportGlowParticle.start()
}
}
function deactivateTeleport() {
if(level.state === "teleporting"){
level.toggleTeleport()
audioManager.play(audioManager.idSLOWMOOFF)
player.teleportGlowParticle.stop()
}
}
Image {
id: scoreSign
source: Qt.resolvedUrl("../assets/sign.png")
width: 150
height: 100
anchors.top: scene.gameWindowAnchorItem.top
anchors.topMargin: -50
anchors.left: scene.gameWindowAnchorItem.left
}
Text {
id: scoreText
x: scoreSign.x+25
y: scoreSign.y+65
text: "Score: " + player.totalScore
font.family: fontHUD.name
font.pixelSize: 22
color: "#f5b68a"
rotation: -2
}
Item {
id: pauseSign
width: pauseSignText.width
height: pauseSignText.height
anchors.top: scene.gameWindowAnchorItem.top
anchors.topMargin: 10
anchors.horizontalCenter: parent.horizontalCenter
MenuText {
id: pauseSignText
color: "black"
opacity: 0.5
text: "II"
font.pixelSize: 30
}
MouseArea {
anchors.fill: parent
onClicked: {
parent.scale = 1.0
pauseGame()
}
onPressed: {
parent.scale = 0.85
}
onReleased: {
parent.scale = 1.0
}
onCanceled: {
parent.scale = 1.0
}
}
}
Image {
source: Qt.resolvedUrl("../assets/sign.png")
width: 150
height: 130
anchors.top: scene.gameWindowAnchorItem.top
anchors.topMargin: -65
mirror: true
anchors.right: scene.gameWindowAnchorItem.right
}
Image {
id: teleportImage
source: Qt.resolvedUrl("../assets/teleport.png")
anchors.top: scene.gameWindowAnchorItem.top
anchors.topMargin: 12
anchors.right: scene.gameWindowAnchorItem.right
anchors.rightMargin: 100
opacity: teleportCount > 0 ? 1 : 0.2
width: 35
height: 30
}
Text {
id: teleportText
anchors.top: teleportImage.bottom
anchors.topMargin: -2
anchors.horizontalCenter: teleportImage.horizontalCenter
text: teleportCount
visible: teleportCount > 0
font.family: fontHUD.name
font.pixelSize: 14
color: "#f5b68a"
}
Image {
id: parachuteImage
source: Qt.resolvedUrl("../assets/parachute.png")
anchors.top: scene.gameWindowAnchorItem.top
anchors.topMargin: 15
anchors.right: scene.gameWindowAnchorItem.right
anchors.rightMargin: 60
opacity: parachuteCount > 0 ? 1 : 0.2
width: 28
height: 28
}
Text {
id: parachuteText
anchors.top: parachuteImage.bottom
anchors.topMargin: -2
anchors.horizontalCenter: parachuteImage.horizontalCenter
text: parachuteCount
visible: parachuteCount > 0
font.family: fontHUD.name
font.pixelSize: 14
color: "#f5b68a"
}
Image {
id: x2Image
source: Qt.resolvedUrl("../assets/x2.png")
anchors.top: scene.gameWindowAnchorItem.top
anchors.topMargin: 18
anchors.right: scene.gameWindowAnchorItem.right
anchors.rightMargin: 20
opacity: player.doublePointsTime > 0 ? 1 : 0.2
width: 25
height: 25
}
Text {
id: xText
anchors.top: x2Image.bottom
anchors.horizontalCenter: x2Image.horizontalCenter
text: player.doublePointsTime
visible: player.doublePointsTime > 0
font.family: fontHUD.name
font.pixelSize: 14
color: "#f5b68a"
}
NewLevel{
id: newLevelMessage
anchors.centerIn: parent
}
ItemEditor {
id: itemEditor
visible: false
opacity: 0.85
z:20
width: scene.width-45
}
Rectangle {
id: itemEditorMenu
color: "grey"
width: 40
height: 70
y: 70
anchors.right: scene.right
opacity: 0.5
visible: developerBuild
enabled: visible
z: 50
MouseArea {
anchors.fill: parent
onClicked: {
if(level.state === "running") {
level.pauseGame()
}
else if(level.state === "paused") {
level.resumeGame()
}
itemEditor.visible = itemEditor.visible ? false : true
}
}
Text {
text: "ItemEditor"
rotation: -90
font.pixelSize: 12
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right
anchors.rightMargin: -5
}
}
Rectangle {
anchors.top: itemEditorMenu.bottom
anchors.topMargin: 10
anchors.right: parent.right
color: "grey"
width: 40
height: 40
opacity: 0.5
visible: developerBuild
enabled: visible
Text {
font.pixelSize: 15
text: level.difficulty
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
if(level.difficulty >=6)
level.difficulty = 0
else
level.difficulty++
}
}
}
SaveItDialog {
id: saveitDialog
anchors.centerIn: parent
onActivated: {
scoreText.opacity = 0.5
teleportText.opacity = 0.5
parachuteText.opacity = 0.5
xText.opacity = 0.5
}
onDeactivated: {
scoreText.opacity = 1
teleportText.opacity = 1
parachuteText.opacity = 1
xText.opacity = 1
}
onSaveIt: {
visible = false
player.x = scene.width/2
player.y = scene.height/2-level.y
level.saveIt()
audioManager.play(audioManager.idSLOWMO)
}
onKillIt: {
player.killIt()
}
}
onBackButtonPressed: {
if(level.state !== "teleporting" && !saveitDialog.visible) {
audioManager.play(audioManager.idMENUCLICK)
level.pauseGame();
showPauseBackground.start()
}
}
Timer {
id: showPauseBackground
interval: 250
onTriggered: {
NativeUtils.displayMessageBox(qsTr("Return to menu?"), "", 2);
}
}
Timer {
id: showPausedGame
interval: 250
onTriggered: {
messageBox = "resume"
NativeUtils.displayMessageBox(qsTr("Resume?"), "", 1);
}
}
function enterScene() {
level.startGame();
}
function pauseGame() {
if(level.state !== "running")
return
level.pauseGame()