ChickenOutbreak2 Demo
import QtQuick 2.0
import Felgo 4.0
SceneBase {
id: mainScene
property bool exitDialogShown: false
property bool vplayLinkShown: false
onBackButtonPressed: {
audioManager.play(audioManager.idMENUCLICK)
exitDialogShown = true
NativeUtils.displayMessageBox(qsTr("Really quit the game?"), "", 2);
}
Connections {
target: window.activeScene === mainScene ? NativeUtils : null
function onMessageBoxFinished(accepted) {
audioManager.play(audioManager.idMENUCLICK)
console.debug("the user confirmed the Ok/Cancel dialog with:", accepted)
if(accepted && exitDialogShown) {
entityManager.removeAllPooledEntities()
Qt.quit()
} else if(accepted && vplayLinkShown) {
flurry.logEvent("MainScene.Show.VPlayWeb")
NativeUtils.openUrl("https://felgo.com/showcases/?utm_medium=game&utm_source=chicken_outbreak2&utm_campaign=chicken_outbreak2#chicken_outbreak2");
}
exitDialogShown = false
vplayLinkShown = false
}
}
MultiResolutionImage {
source: Qt.resolvedUrl("../assets/background-wood2.png")
width: parent.width
height: parent.height
}
MainSceneDecoration {}
Image {
source: Qt.resolvedUrl("../assets/sign-chickenoutbreak2.png")
anchors.horizontalCenter: parent.horizontalCenter
y: -118
width: 300
height: 270
z: 20
}
property int signRotationPrefix: accelerometer.active ? (accelerometer.reading.x >= 0 ? 1 : -1) : 0
property real signRotation: accelerometer.active ? (Math.abs(accelerometer.reading.x) > 1 ? (accelerometer.reading.x - signRotationPrefix) * 2 : 0) : 0
Image {
id: gameNetworkSign
source: Qt.resolvedUrl("../assets/sign.png")
anchors.horizontalCenter: parent.horizontalCenter
width: 150
height: 120
mirror: true
y:80
z:19
rotation: signRotation
visible: false
Item {
y: 82
anchors.horizontalCenter: parent.horizontalCenter
width: highscoreText.width+scoreImage.width+highscoreTextScore.width
rotation: 2
MenuText {
id: highscoreText
text: qsTr("Highscore:")
font.pixelSize: 20
}
Image {
id: scoreImage
source: Qt.resolvedUrl("../assets/gamecenter.png")
y: 1
width: 20
height: 20
anchors.left: highscoreText.right
anchors.leftMargin: 1
}
MenuText {
id: highscoreTextScore
text: ""+ maximumHighscore
font.pixelSize: 20
anchors.left: scoreImage.right
anchors.leftMargin: 5
}
}
MouseArea {
anchors.bottom: parent.bottom
width: parent.width
height: parent.height/2
onClicked: {
parent.scale = 1.0
audioManager.play(audioManager.idMENUCLICK)
window.state = "gameNetwork"
gameNetwork.showLeaderboard()
}
onPressed: {
parent.scale = 0.85
}
onReleased: {
parent.scale = 1.0
}
onCanceled: {
parent.scale = 1.0
}
}
}
Image {
source: Qt.resolvedUrl("../assets/sign.png")
anchors.horizontalCenter: parent.horizontalCenter
width: 100
height: 85
y:105
z:18
rotation: signRotation
MenuText {
id: shopShield
anchors.left: parent.left
anchors.leftMargin: 20
y: 55
text: qsTr("Shop ")
font.pixelSize: 20
rotation: -2
}
CoinDisplay {
y: 55
anchors.left: shopShield.right
rotation: -2
}
MouseArea {
anchors.bottom: parent.bottom
width: parent.width
height: parent.height/2
onClicked: {
parent.scale = 1.0
audioManager.play(audioManager.idMENUCLICK)
window.state = "shop"
}
onPressed: {
parent.scale = 0.85
}
onReleased: {
parent.scale = 1.0
}
onCanceled: {
parent.scale = 1.0
}
}
}
MenuButton {
text: qsTr("Play")
onClicked: {
audioManager.play(audioManager.idMENUCLICK)
if(firstAppStart) window.state = "tutorial"
else window.state = "game"
}
anchors.horizontalCenter: parent.horizontalCenter
textSize: 27
width: 170 * 0.8
height: 60 * 0.8
y: 290
}
Column {
anchors.horizontalCenter: parent.horizontalCenter
y: 345
spacing: 5
MenuButton {
text: qsTr("Credits")
anchors.horizontalCenter: parent.horizontalCenter
width: 170 * 0.6
height: 60 * 0.6
onClicked: {
audioManager.play(audioManager.idMENUCLICK)
window.state = "credits";
}
}
Item {
width: 90
height: 60 * 0.6
anchors.horizontalCenter: parent.horizontalCenter
MusicButton {
}
SoundButton {
x: 50
}
}
Item {
width: 90
height: 60 * 0.6
anchors.horizontalCenter: parent.horizontalCenter
SocialMediaButton {
id: facebook
source: Qt.resolvedUrl("../assets/facebook.png")
onClicked: {
audioManager.play(audioManager.idMENUCLICK)
NativeUtils.openUrl("https://apps.facebook.com/chicken_outbreak_two")
}
}
SocialMediaButton {
id: twitter
x: 50
source: Qt.resolvedUrl("../assets/twitter.png")
onClicked: {
audioManager.play(audioManager.idMENUCLICK)
NativeUtils.openUrl("https://twitter.com/ChickenOutbreak")
}
}
}
}
DailyBonus {
id: dailyBonus
anchors.horizontalCenter: parent.horizontalCenter
y: 248
}
HourlyBonus {
id: hourlyBonus
anchors.horizontalCenter: parent.horizontalCenter
y: 248
}
Image {
id: logo
anchors.right: mainScene.gameWindowAnchorItem.right
anchors.rightMargin: 10
anchors.bottom: mainScene.gameWindowAnchorItem.bottom
anchors.bottomMargin: 10
source: Qt.resolvedUrl("../assets/felgo-logo.png")
fillMode: Image.PreserveAspectFit
height: 55
MouseArea {
anchors.fill: parent
onClicked: {
audioManager.play(audioManager.idMENUCLICK)
vplayLinkShown = true
flurry.logEvent("MainScene.ShowDialog.VPlayWeb")
NativeUtils.displayMessageBox(qsTr("Felgo"), qsTr("This game is built with Felgo. The source code is available in the free Felgo SDK - so you can build your own Chicken Outbreak 2 in minutes! Visit Felgo.net now?"), 2)
}
}
SequentialAnimation {
running: true
loops: -1
NumberAnimation { target: logo; property: "opacity"; to: 0.1; duration: 1200 }
NumberAnimation { target: logo; property: "opacity"; to: 1; duration: 1200 }
}
}
function enterScene() {
opacity = 1
var today = new Date()
var todayTruncated = new Date(today.getTime()-today.getHours()*3600000-today.getMinutes()*60000-today.getSeconds()*1000-today.getMilliseconds())
console.debug("Today truncated is " + todayTruncated.getTime().toString())
var storedLastLoginMS = settings.getValue("lastLogin")
console.debug("Read from database " + storedLastLoginMS)
if(!storedLastLoginMS) {
settings.setValue("lastLogin",todayTruncated.getTime().toString())
dailyBonus.giveBonus()
console.debug("Set lastLogin to" + settings.getValue("lastLogin"))
} else {
if(todayTruncated.getTime().toString() > storedLastLoginMS) {
console.debug("Last login was a day ago, give player bonus")
settings.setValue("lastLogin",todayTruncated.getTime().toString())
dailyBonus.giveBonus()
}
}
lockTimer.restart()
}
Timer {
id: lockTimer
interval: 500
onTriggered: {
lockArea.enabled = false
}
}
MouseArea {
id: lockArea
anchors.fill: parent
enabled: true
onClicked: {