Squaby Demo
import QtQuick 2.0
import Felgo 4.0
import "otherScenes"
import "gameScene"
import "levels"
import "common"
Item {
property alias level: gameSceneLoader.level
property alias levelScene: levelScene
property alias hud: gameSceneLoader.hud
property bool createdNewLevel: false
property bool editAuthorLevel: false
property bool reloadLevel: false
Player {
id: player
}
property string lastActiveState: ""
onStateChanged: {
if(lastActiveState === "main") {
flurry.endTimedEvent("Display.Main");
} else if(lastActiveState === "game") {
flurry.endTimedEvent("Display.Game");
} else if(lastActiveState === "pause") {
flurry.endTimedEvent("Display.Pause");
} else if(lastActiveState === "credits") {
flurry.endTimedEvent("Display.Credits");
} else if(lastActiveState === "gameOver") {
flurry.endTimedEvent("Display.GameOver");
} else if(lastActiveState === "levels") {
flurry.endTimedEvent("Display.Levels");
} else if(lastActiveState === "waveDefeated") {
flurry.endTimedEvent("Display.waveDefeated");
}
if(state === "main") {
flurry.logTimedEvent("Display.Main");
} else if(state === "game") {
flurry.logTimedEvent("Display.Game");
} else if(state === "pause") {
flurry.logTimedEvent("Display.Pause");
} else if(state === "credits") {
flurry.logTimedEvent("Display.Credits");
} else if(state === "gameOver") {
flurry.logTimedEvent("Display.GameOver");
var objectWithPlayerProperties = {};
player.addPlayerPropertiesToAnalyticsObject(objectWithPlayerProperties);
flurry.logEvent("Game.Finished", objectWithPlayerProperties);
} else if(state === "levels") {
flurry.logTimedEvent("Display.Levels");
} else if(state === "waveDefeated") {
flurry.logTimedEvent("Display.waveDefeated");
}
lastActiveState = state;
}
SquabyGameNetwork {
id: gameNetwork
}
function reloadUserBestLevelStats() {
console.debug("reloadUserBestLevelStats() called")
if(gameNetwork.userInitiallyInSync) {
levelEditor.loadBestLevelStats()
}
}
SquabyLevelStore {
id: levelStore
levelEditorItem: levelEditor
}
FacebookConnector {
id: facebook
}
property variant scene: gameSceneLoader.item ? gameSceneLoader.item : {}
Loader {
id: gameSceneLoader
property variant level: item ? item.level : {}
property variant hud: item ? item.hud : {}
property variant entityContainer: item ? item.entityContainer : undefined
onLoaded: {
console.debug("SquabyMain: SquabyScene loaded")
}
}
LoadingScene {
id: loadingScene
onFinishedLoadingAnimation: {
console.debug("LoadingScene: finishedLoadingAnimation, set gameScene source to SquabyScene (this might be a lenghty operation the first time loaded!)")
gameSceneLoader.source="gameScene/SquabyScene.qml"
twoPhaseLevelLoader.startGameAfterLevelLoadingAnimationFinished()
}
}
DefeatedScene {
id: waveDefeatedScene
onRestartGame: {
flurry.logEvent("Defated.Restart","Level",levelEditor.currentLevelNameString)
if(!levelStore.noAdsGood.purchased)
chartboostView.doNotShowAdvert()
scene.restartGame()
}
onContinueGame: {
flurry.logEvent("Defated.ContinuesGame","Level",levelEditor.currentLevelNameString)
if(!levelStore.noAdsGood.purchased)
chartboostView.doNotShowAdvert()
scene.continueGame()
}
onNextLevel: {
flurry.logEvent("Defated.NextLevel","Level",levelEditor.currentLevelNameString)
if(!levelStore.noAdsGood.purchased)
chartboostView.doNotShowAdvert()
scene.nextLevel()
}
onGameOver: {
flurry.logEvent("Defated.GameOver","Level",levelEditor.currentLevelNameString)
if(!levelStore.noAdsGood.purchased)
chartboostView.doNotShowAdvert()
scene.exitScene()
}
onBackButtonPressed: {
flurry.logEvent("Defated.BackPressed","Level",levelEditor.currentLevelNameString)
if(!levelStore.noAdsGood.purchased)
chartboostView.doNotShowAdvert()
}
onShowHighscoreForLevel: {
gameNetwork.showLeaderboard(leaderboard)
vplayGameNetworkScene.cameFromScene = "waveDefeated"
window.state = "gameNetwork"
flurry.logEvent("Level.ShowHighscore","leaderboard",leaderboard)
}
}
property alias creditsScene: creditsSceneLoader.item
Loader {
id: creditsSceneLoader
}
LevelSelectionScene {
id: levelScene
onBackClicked: window.state = "main"
onNewLevelClicked: {
for(var ii = 0; ii < levelEditor.applicationJSONLevels.length; ++ii) {
if(levelEditor.applicationJSONLevels[ii].levelName === "MyLevel") {
createdNewLevel = true
twoPhaseLevelLoader.startLoadingLevel(false,levelEditor.applicationJSONLevels[ii])
}
}
flurry.logEvent("LevelSelection.NewLevel")
}
onShowProfileView: {
vplayGameNetworkScene.cameFromScene = "selectLevel"
window.state = "gameNetwork"
gameNetwork.showProfileView()
flurry.logEvent("LevelSelection.ShowProfile")
}
onShowHighscoreForLevel: leaderboard => {
gameNetwork.showLeaderboard(leaderboard)
vplayGameNetworkScene.cameFromScene = "selectLevel"
window.state = "gameNetwork"
flurry.logEvent("LevelSelection.ShowHighscore","leaderboard",leaderboard)
}
}
MainMenuScene {
id: mainMenuScene
onPlayClicked: {
flurry.logEvent("MainMenu.Play")
levelScene.storageLocation = levelEditor.applicationJSONLevelsLocation
window.state = "levels"
}
onMyLevelsClicked: {
flurry.logEvent("MainMenu.Levels")
levelScene.storageLocation = levelEditor.authorGeneratedLevelsLocation
window.state = "levels"
}
onCreditsClicked: {
flurry.logEvent("MainMenu.Credits")
creditsSceneLoader.source = "otherScenes/CreditsScene.qml"
window.state = "credits"
}
onGameNetworkViewClicked: {
flurry.logEvent("MainMenu.GameNetwork")
gameNetwork.showProfileView()
vplayGameNetworkScene.cameFromScene = "menu"
window.state = "gameNetwork"
}
}
FelgoGameNetworkScene {
id: vplayGameNetworkScene
onBackButtonPressed: {
flurry.logEvent("GameNetwork.BackPressed","from",cameFromScene)
if(cameFromScene === "menu") {
window.state = "main"
} else if(cameFromScene === "selectLevel"){
window.state = "levels"
} else if(cameFromScene === "waveDefeated") {
window.state = "waveDefeated"
}
}
}
AchievementOverlay {
id: achievementOverlay
z: 100
}
property alias levelEditor: squabyLevelEditor
SquabyLevelEditor {
id: squabyLevelEditor
entityManagerItem: entityManager
}
ChartboostView {
id: chartboostView
}
EntityManager {
id: entityManager
entityContainer: gameSceneLoader.entityContainer
poolingEnabled: true
dynamicCreationEntityList: [
Qt.resolvedUrl("entities/Obstacle.qml") + "",
]
}
TwoPhaseLevelLoader {
id: twoPhaseLevelLoader
}
Component.onCompleted: {
lockAllLevels()
}
function pauseGame() {
if(state === "game" && gameSceneLoader.item) {
gameSceneLoader.item.showPauseScene()
}
}
function lockAllLevels() {
var levelInit = settings.getValue("levelsInit")
if(levelInit === undefined) {
settings.setValue("levelsInit", true)
settings.setValue(3863, true)
settings.setValue(7335, true)
settings.setValue(6849, true)
settings.setValue(1805, true)
settings.setValue(7612, true)
settings.setValue(130, true)
settings.setValue(8646, true)
settings.setValue(9201, true)
settings.setValue(5840, true)
}
}
function unlockNextLevel(currentLevel) {
if(currentLevel === "Level 1") {
settings.setValue(3863, false)
return true
} else if(currentLevel === "Level 2") {
settings.setValue(7335, false)
return true
} else if(currentLevel === "Level 3") {
if(!settings.getValue(3863)) {
settings.setValue(6849, false)
return true
}
return false
} else if(currentLevel === "Level 4") {
if(!settings.getValue(7335)) {
settings.setValue(1805, false)
return true
}
return false
} else if(currentLevel === "Level 5") {
if(!settings.getValue(6849)) {
settings.setValue(7612, false)
return true
}
return false
} else if(currentLevel === "Level 6") {
if(!settings.getValue(1805)) {
settings.setValue(130, false)
return true
}
return false
} else if(currentLevel === "Level 7") {
if(!settings.getValue(7612)) {
settings.setValue(8646, false)
return true
}
return false
} else if(currentLevel === "Level 8") {
if(!settings.getValue(130)) {
settings.setValue(9201, false)
return true
}
return false
} else if(currentLevel === "Level 9") {
if(!settings.getValue(8646)) {
settings.setValue(5840, false)
return true
}
return false
} else if(currentLevel === "Level 10") {
return false
}
}
function unlockLevel(name) {
if(name === "Level 1") {
settings.setValue(3863, false)
} else if(name === "Level 2") {
settings.setValue(3863, false)
} else if(name === "Level 3") {
settings.setValue(7335, false)
} else if(name === "Level 4") {
settings.setValue(6849, false)
} else if(name === "Level 5") {
settings.setValue(1805, false)
} else if(name === "Level 6") {
settings.setValue(7612, false)
} else if(name === "Level 7") {
settings.setValue(130, false)
} else if(name === "Level 8") {
settings.setValue(8646, false)
} else if(name === "Level 9") {
settings.setValue(9201, false)
} else if(name === "Level 10") {
settings.setValue(5840, false)
}
}
function isBuyable(currentLevel) {
if(currentLevel === "Level 2" && settings.getValue(3863)) {
return true
} else if(currentLevel === "Level 3" && settings.getValue(7335) && !settings.getValue(3863)) {
return true
} else if(currentLevel === "Level 4" && settings.getValue(6849) && !settings.getValue(7335)) {
return true
} else if(currentLevel === "Level 5" && settings.getValue(1805) && !settings.getValue(6849)) {
return true
} else if(currentLevel === "Level 6" && settings.getValue(7612) && !settings.getValue(1805)) {
return true
} else if(currentLevel === "Level 7" && settings.getValue(130) && !settings.getValue(7612)) {
return true
} else if(currentLevel === "Level 8" && settings.getValue(8646) && !settings.getValue(130)) {
return true
} else if(currentLevel === "Level 9" && settings.getValue(9201) && !settings.getValue(8646)) {
return true
} else if(currentLevel === "Level 10" && settings.getValue(5840) && !settings.getValue(9201)) {
return true
}
return false
}
function isCommunityLevel(currentLevel) {
switch(currentLevel) {
case "Level 1":
case "Level 2":
case "Level 3":
case "Level 4":
return false
case "Level 5":
case "Level 6":
case "Level 7":
case "Level 8":
case "Level 9":
return false
default:
return true
}
}
function activateMain() {
state = "main"
}
states: [
State {
name: "main"
PropertyChanges { target: mainMenuScene; opacity: 1}
StateChangeScript {
script: {
var lastActiveScene = window.activeScene
window.activeScene = mainMenuScene
console.debug("SquabyMain: change to state 'main'")
mainMenuScene.enterScene();
backgroundMusic.play();
if(lastActiveScene === waveDefeatedScene || lastActiveScene === scene ) {
scene.exitScene()
}
}
}
},
State {
name: "game"
PropertyChanges { target: scene; opacity: 1}
StateChangeScript {
script: {
console.debug("SquabyMain: change to state 'game'")
window.activeScene = scene
scene.enterScene();
backgroundMusic.play();
loadingScene.state = "exited"
}
}
},
State {
name: "loading"
PropertyChanges { target: loadingScene; opacity: 1}
StateChangeScript {
script: {
window.activeScene = loadingScene
loadingScene.enterScene();
}
}
},
State {
name: "pause"
PropertyChanges { target: scene; opacity: 1}
PropertyChanges { target: waveDefeatedScene; opacity: 1}
StateChangeScript {
script: {
window.activeScene = waveDefeatedScene
waveDefeatedScene.enterScene();
}
}
},
State {
name: "credits"
PropertyChanges { target: creditsScene; opacity: 1}
StateChangeScript {
script: {
window.activeScene = creditsScene
creditsScene.enterScene();
}
}
},
State {
name: "gameNetwork"
PropertyChanges {target: vplayGameNetworkScene; opacity: 1}
StateChangeScript {
script: {
window.activeScene = vplayGameNetworkScene
}
}
},
State {
name: "gameover"
PropertyChanges { target: scene; opacity: 1}
PropertyChanges { target: waveDefeatedScene; opacity: 1}
StateChangeScript {
script: {
window.activeScene = waveDefeatedScene
waveDefeatedScene.enterScene();
}
}
},
State {
name: "levels"
PropertyChanges { target: levelScene; opacity: 1}
StateChangeScript {
script: {
window.activeScene = levelScene
levelScene.enterScene();
}
}
},
State {
name: "waveDefeated"
PropertyChanges { target: scene; opacity: 1}
PropertyChanges { target: waveDefeatedScene; opacity: 1}
StateChangeScript {
script: {
window.activeScene = waveDefeatedScene
waveDefeatedScene.enterScene();
}
}
}
]
transitions: [
Transition {
from: "main"
animations: mainMenuFadeAnimation
},
Transition {
from: ""
to: "main"
PropertyAnimation { target: mainMenuScene; property: "opacity"; duration: 1000 }
}
]
NumberAnimation {
id: mainMenuFadeAnimation
target: mainMenuScene
duration: 900
property: "opacity"