GameOverScene.qml Example File

demos/ChickenOutbreak2/qml/GameOverScene.qml
 import QtQuick 2.0
 import Felgo 3.0

 // gets displayed when the game is lost, and shows the reached score and if there was a new highscore reached
 SceneBase {
   id: gameOverScene

   onBackButtonPressed: {
     prepareSceneExit()
     window.state = "main"
   }

   Component.onCompleted: opacity = 1.0

   property int moneyEarned : 0
   property bool newMaximumHighscore: false
   property alias achievementOverlay: achievementOverlay

   // 3 different formats of the image are provided (-sd, -hd and -hd2)
   MultiResolutionImage {
     source: "../assets/gameOverScreen.png"
     anchors.centerIn: parent
   }

   Image {
     source: "../assets/sign.png"
     anchors.horizontalCenter: parent.horizontalCenter
     y: -118
     width: 300
     height: 270
     z: 20

     MenuText {
       id: bestScoreText
       anchors.top: parent.top
       anchors.topMargin: 172
       anchors.horizontalCenter: parent.horizontalCenter
       text: (newMaximumHighscore ? qsTr("New Highscore ") : qsTr("Score ")) + lastScore
       font.pixelSize: 45
       rotation: -1.5
     }
     MenuText {
       id: yourScoreText
       anchors.top: bestScoreText.bottom
       anchors.topMargin: 1
       anchors.horizontalCenter: parent.horizontalCenter
       text: gameNetwork.userPositionForCurrentActiveLeaderboard === 1 ? ( lastScore >= gameNetwork.userHighscoreForCurrentActiveLeaderboard ? qsTr("You are world leader") : qsTr("You are still world leader")) : ((positionChange>0) ? (qsTr(" You improved by ")+ positionChange + ((positionChange > 1) ? qsTr(" Ranks"): + qsTr(" Rank"))) : qsTr("Continue and enHENce"))
       font.pixelSize: 22
       rotation: -1.5
     }

     MouseArea {
       anchors.fill: parent
       onClicked: {
         prepareSceneExit()
         window.state = "gameNetwork"
         // this would not need to be called, then no request is sent when showing it every time
         gameNetwork.showLeaderboard()
         parent.scale = 1.0
       }
       onPressed: {
         parent.scale = 0.85
       }
       onReleased: {
         parent.scale = 1.0
       }
       onCanceled: {
         parent.scale = 1.0
       }
     }
   }

   Image {
     source: "../assets/sign.png"
     anchors.horizontalCenter: parent.horizontalCenter
     width: 150
     height: 120
     mirror: true
     y:80
     z:19

     MouseArea {
       anchors.fill: parent
       onClicked: {
         prepareSceneExit()
         window.state = "gameNetwork"
         // this would not need to be called, then no request is sent when showing it every time
         gameNetwork.showLeaderboard()
         parent.scale = 1.0
       }
       onPressed: {
         parent.scale = 0.85
       }
       onReleased: {
         parent.scale = 1.0
       }
       onCanceled: {
         parent.scale = 1.0
       }
     }

     Item {
       y: 82
       anchors.horizontalCenter: parent.horizontalCenter
       width:  highscoreText.width+scoreImage.width+highscoreTextScore.width
       rotation: 2

       MenuText {
         id: highscoreText
         text: qsTr("Rank: ") +gameNetwork.userPositionForCurrentActiveLeaderboard
         font.pixelSize: 20
       }
       Image {
         id: scoreImage
         source: "../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
       }
     }
   }

   Image {
     source: "../assets/sign.png"
     anchors.horizontalCenter: parent.horizontalCenter
     width: 140
     height: 115
     y:169
     z:18

     Item {
       width: shopText.width + coinDisplay.width+2
       height: shopText.height
       y: 80

       anchors.horizontalCenter: parent.horizontalCenter
       rotation: -2.0

       MenuText {
         id: shopText
         text: qsTr("Shop")
         font.pixelSize: 20
       }

       CoinDisplay {
         id: coinDisplay
         anchors.left: shopText.right
         anchors.leftMargin: 2
         displayBonusCoins: true
         bonusCoins: moneyEarned
       }
     }

     MouseArea {
       anchors.fill: parent
       onClicked: {
         hen.scale = 1.0
         parent.scale = 1.0
         prepareSceneExit()
         window.state = "shop"
       }
       onPressed: {
         hen.scale = 0.85
         parent.scale = 0.85
       }
       onReleased: {
         hen.scale = 1.0
         parent.scale = 1.0
       }
       onCanceled: {
         hen.scale = 1.0
         parent.scale = 1.0
       }
     }
   }

   Image {
     // position manually so it is in the center of the egg
     id: hen
     x: 135
     y: 191
     width: 50
     height: 50
     source: store.blackHen.purchased ? "../assets/chicken2-dead.png" : "../assets/chicken4-dead.png"
   }

   MenuButton {
     id: playagainbutton
     width: 170
     height: 50
     anchors.bottom: returnButton.top
     anchors.bottomMargin: 10
     anchors.horizontalCenter: parent.horizontalCenter
     text: qsTr("Play again")
     onClicked: {
       prepareSceneExit()
       window.state = "game"
     }
   }

   MenuButton {
     id: returnButton
     width: 170
     height: 50
     anchors.bottom: parent.bottom
     anchors.bottomMargin: 20
     anchors.horizontalCenter: parent.horizontalCenter
     text: qsTr("Back to Menu")
     onClicked: {
       prepareSceneExit()
       window.state = "main"
     }
   }

   MenuButton {
     id: tutorialButton
     width: 40
     height: 40
     anchors.right: gameOverScene.gameWindowAnchorItem.right
     anchors.rightMargin: 2
     anchors.bottom: gameOverScene.gameWindowAnchorItem.bottom
     anchors.bottomMargin: 2
     text: qsTr("")
     onClicked: {
       prepareSceneExit()
       window.state = "tutorial"
     }

     Image {
       width: 30
       height: 30
       source: "../assets/help.png"
       anchors.centerIn: parent
     }
   }

   AchievementOverlay {
     id: achievementOverlay
     width: parent.gameWindowAnchorItem.width
     height: 80
     anchors.left: parent.gameWindowAnchorItem.left
     anchors.top: parent.gameWindowAnchorItem.top
     opacity: 0.0
     z:21
   }

   function prepareSceneExit() {
     audioManager.play(audioManager.idMENUCLICK)
     chartboostView.doNotShowAdvert()
     positionChange = 0
   }

   function enterScene() {

     if(!store.noAdsGood.purchased && !system.desktopPlatform) {
       if(!advertDeaths) {
         chartboostView.showAdvertIfAvailable()
       }
       advertDeaths++
       if(advertDeaths>=maxAdvertDeaths) {
         advertDeaths = 0
       }
     }

     var earned = Math.floor(lastScore/1000)
     if(earned > 0) {
       moneyEarned = earned
       store.giveItem("currency_money_id",moneyEarned)
       audioManager.play(audioManager.idPLING)
     } else {
       moneyEarned = 0
     }

     newMaximumHighscore = false
     if(lastScore > maximumHighscore) {
       maximumHighscore = lastScore;
       newMaximumHighscore = true;
     } else {
       newMaximumHighscore = false;
     }
     // Check achievements
     var grains = player.collectedGrains;
     var badGrains = player.collectedBadGrains
     var parachutes = player.parachutes;
     var beams = player.beams;
     var deaths = player.deaths;

     console.log("Collected grains:", grains);

     if (grains >= 10) {
       // it gets reported both to VPGN and GameCenter with this call, because gameCenterItem was set!
       gameNetwork.unlockAchievement("cob2_grains10", true)
     }
     if (grains >= 25) {
       gameNetwork.unlockAchievement("cob2_grains25", true)
     }
     if (grains >= 50) {
       gameNetwork.unlockAchievement("cob2_grains50", true)
     }
     if (grains >= 100) {
       gameNetwork.unlockAchievement("cob2_grains100", true)
     }
     if(badGrains >= 10) {
       gameNetwork.unlockAchievement("cob2_badgrains10",true)
     }
     if (deaths >= 10){
       gameNetwork.unlockAchievement("cob2_chickendead1", true)
     }
     if (parachutes >= 10){
       gameNetwork.unlockAchievement("cob2_parachute10", true)
     }
     if (beams >= 10){
       gameNetwork.unlockAchievement("cob2_teleported10", true)
     }

     console.log("Player's death count:", deaths);
   }
 }

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support