Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Squaby Demo

 import QtQuick 2.0
 import Felgo 4.0

 Item {
   property int squabyRedCounter: 0
   property bool giveMoney: false
   property bool waitForRangeUpgrade: false
   property bool waitForFireUpgrade: false
   property bool waitForNextWave: false
   property bool waitForNextTower: false
   property variant towerPosition: Qt.point(0,0)
   property bool upgradeAllowed: false

   property bool dialogPauseState: false
   property bool actionPauseState: false
   property bool particlePauseState: false
   property bool tutorialFinished: false
   property bool towerRangeCurrentlyVisible: false

   function reset() {
     squabyRedCounter = 0
     giveMoney = false
     waitForRangeUpgrade = false
     waitForFireUpgrade = false
     waitForNextWave = false
     towerPosition = Qt.point(0,0)
     upgradeAllowed = false
     // dialog setttings
     dialog.dialogText = ""
     dialog.showButtonWhenFinished = false
     dialogBox.visible = false
     action.visible = false
     waitForNextTower = false
     tutorialFinished = false
     tutorialFinishedTimer.stop()
 //    if(notificationParticle.running) {
 //      notificationParticle.stopLivingParticles()
 //    }
     towerRangeCurrentlyVisible = false
   }

   function pause() {
     // save state
     dialogPauseState = dialogBox.visible
     actionPauseState = action.visible
     // set invisible
     dialogBox.visible = false
     action.visible = false
     if(tutorialFinishedTimer.running) {
       tutorialFinishedTimer.stop()
       dialogPauseState = false
     }
 //    particlePauseState = notificationParticle.running
 //    if(notificationParticle.running) {
 //      notificationParticle.stopLivingParticles()
 //    }
   }

   function resume() {
     // resume states
     dialogBox.visible = dialogPauseState
     action.visible = actionPauseState
     squabyCreator.start()
 //    if(particlePauseState) {
 //      notificationParticle.start()
 //    }
   }

   function nextAction(source,action,position) {
     //console.debug("[TutorialsFlamethrower]",source,action)
     if(tutorialFinished) {
       return true
     }

     if(source === "startClock" && action === "startGame") {
       activateSquabyCreation(false)
       setAction(true,deltaX+(developerBuild ? 0 : 32)+415,deltaY+242)
       dialog.activateMessage(["Drag & Drop the Flamethrower to the room!"])
     } else if(source === "flamethrower" && action === "pressed") {
       setAction(false,0,0)
       dialog.activateMessage(["The circle gets green in places you can build the tower."])
     } else if(source === "flamethrower" && action === "entityBuilt") {
       if(!waitForNextTower) {
         if(position) {
           towerPosition = position
         }

         dialog.activateMessage(["Kill orange and red Squabies with flamethrowers!"])
         squabyCreator.createNextSingleSquabyImmediately()
       } else {
         dialog.activateMessage(["You finished the tutorial! Now you can act free!"])
         tutorialFinished = true
         tutorialFinishedTimer.start()
         activateSquabyCreation(true)
         upgradeAllowed = true
       }
     } else if(source === "squabyOrange" && action === "died") {
       squabyRedCounter++
       if(squabyRedCounter == 1) {
         setAction(true,deltaX+64,deltaY+242)
         dialog.activateMessage(["You can trigger the next Squaby instantly to gain more points by pressing the wave button after the tutorial!"])
         waitForNextWave = true
       } else if(squabyRedCounter == 2) {
         activateFireUpgrade()
       } else if(squabyRedCounter == 4) {
         activateSquabyCreation(false)
         activateRangeUpgrade()
       } else if(squabyRedCounter == 10) {
         // game would last too long if we would not provide any money here now.
         activateSquabyCreation(false)
         dialog.activateMessage(["You should build another tower for the next wave! Here use some additional gold!"])
         player.gold = 50
         waitForNextTower = true
       }
     } else if(source === "squabyCreator" && action === "immediately" && waitForNextWave) {
       squabyCreator.createNextSingleSquabyImmediately()
       waitForNextWave = false
       dialogBox.visible = false
       setAction(false,0,0)
       // avoid showing not allowed message
       return true
     } else if(source === "flamethrower" && action === "clicked" && (waitForRangeUpgrade||waitForFireUpgrade) && upgradeAllowed) {
       activateUpgradeMenuStatus()
     } else if(source === "upgradeButton" && action === "range" && waitForRangeUpgrade) {
       if(!upgradeAllowed) {
         return false
       }

       waitForRangeUpgrade = false
       dialogBox.visible = false
       setAction(false,0,0)
       activateSquabyCreation(true)
       upgradeAllowed = false
     } else if(source === "upgradeButton" && action === "damagePerSecond" && waitForFireUpgrade) {
       if(!upgradeAllowed) {
         return false
       }

       waitForFireUpgrade = false
       dialogBox.visible = false
       setAction(false,0,0)
       activateSquabyCreation(true)
       upgradeAllowed = false
     } else if(source === "upgradeButton" && (action === "damagePerSecond" || action === "range")) {
       return false
     } else if((source === "upgradeButton" && action === "sold") ||
               (source === "squabyCreator" && action === "immediately")) {
       return false
     } else if(source === "towerRange") {
       if(action === "visible") {
         towerRangeCurrentlyVisible = true
 //        if(notificationParticle.running) {
 //          notificationParticle.stopLivingParticles()
 //        }
       } else {
         towerRangeCurrentlyVisible = false
       }
     }
     return true
   }

   function activateRangeUpgrade() {
     upgradeAllowed = true
     waitForRangeUpgrade = true
     // check if player has enough money and provide some if there is not enough to buy the upgrade
     if(player.gold < 15) {
       giveMoney = true
       dialog.showButtonWhenFinished = true
       dialog.activateMessage(["You have not enough gold to buy an upgrade! This time you get some extra credits, but the next time you have kill more Squabies to earn more gold!"])
     } else {
       setRangeUpgrade()
     }
   }

   function activateFireUpgrade() {
     upgradeAllowed = true
     waitForFireUpgrade = true
     // check if player has enough money and provide some if there is not enough to buy the upgrade
     if(player.gold < 35) {
       giveMoney = true
       dialog.showButtonWhenFinished = true
       dialog.activateMessage(["You have not enough gold to buy an upgrade! This time you get some extra credits, but the next time you have kill more Squabies to earn more gold!"])
     } else {
       setFireUpgrade()
     }
   }

   function setRangeUpgrade() {
     dialog.activateMessage(["Click on the tower to open the upgrade menu and buy a range upgrade!"])
     if(!towerRangeCurrentlyVisible) {
       setAction(true,towerPosition.x,towerPosition.y,true)
     } else {
       activateUpgradeMenuStatus()
     }
   }

   function setFireUpgrade() {
     dialog.activateMessage(["Click on the tower to open the upgrade menu and buy a fire upgrade!"])
     if(!towerRangeCurrentlyVisible) {
       setAction(true,towerPosition.x,towerPosition.y,true)
     } else {
       activateUpgradeMenuStatus()
     }
   }

   function activateUpgradeMenuStatus() {
     if(waitForRangeUpgrade) {
       setAction(true,deltaX+(developerBuild ? 0 : 32)+287,deltaY+242)
     } else if(waitForFireUpgrade) {
       setAction(true,deltaX+(developerBuild ? 0 : 32)+352,deltaY+242)
     }
   }

   Timer {
     id: tutorialFinishedTimer
     interval: 3000
     onTriggered: {
       dialogBox.visible = false
     }
   }

   MultiResolutionImage {
     id: dialogBox
     width: dialog.width
     height: dialog.height
     x: 300
     y: 30
     visible: false
     source: Qt.resolvedUrl("../../../assets/img/text-dialog-background.png")
     GameTextDialog {
       id: dialog
       width: 170
       height: 120
       dialogTextDelay: 0
       showButtonWhenFinished: false
       text.color: "white"

       function activateMessage(message) {
         dialog.dialogText = message
         dialogBox.visible = true
       }

       onDialogButtonClicked: {
         if(giveMoney) {
           dialog.showButtonWhenFinished = false
           giveMoney = false
           if(waitForRangeUpgrade) {
             player.gold = 15
             setRangeUpgrade()
           } else if(waitForFireUpgrade) {
             player.gold = 35
             setFireUpgrade()
           } else {
             tutorials.reset()
             tutorials.pause()
             activateSquabyCreation(true)
           }
         }
       }
     }
   }

   function setAction(active,x,y,useParticle) {
     if(useParticle === undefined) {
       action.x = x-action.width/2
       action.y = y-action.height/2
       action.visible = active
     } else {
 //      notificationParticle.x = x
 //      notificationParticle.y = y
       action.visible = !active
 //      notificationParticle.start()
     }
     if(!active) {
 //      if(notificationParticle.running) {
 //        notificationParticle.stopLivingParticles()
 //      }
     }
   }

   function activateSquabyCreation(flag) {
     if(flag) {
       squabyCreator.enabled = true
       squabyCreator.start()
     } else {
       squabyCreator.enabled = false
Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded