MultiplayerDemo
import Felgo 3.0
import QtQuick 2.0
import "scenes"
import "common"
import Qt.labs.settings 1.0
import QtQuick.Dialogs 1.2
GameWindow {
id: window
title: gameNetwork.user.deviceId + " - " + gameNetwork.user.name
Settings {
id: settings
property alias counterAppInstances: gameNetwork.counterAppInstances
Component.onCompleted: {
console.log("settings loaded with counterAppInstances value:"+ counterAppInstances+ ", userName: " +gameNetwork.user.name)
settings.counterAppInstances++
}
}
FelgoGameNetwork {
id: gameNetwork
clearAllUserDataAtStartup: true
gameId: 175
secret: "multiplayerDemo"
gameNetworkView: gameNetworkScene.gnView
user.deviceId: generateDeviceId()
property int counterAppInstances: 0
function generateDeviceId() {
if(system.isPlatform(System.IOS) || system.isPlatform(System.Android) || system.isPlatform(System.WindowsPhone)) {
return system.UDID
}
if(counterAppInstances > 1) {
return system.UDID + "_" + (counterAppInstances) % multiplayer.playerCount
} else {
return system.UDID
}
}
}
FelgoMultiplayer {
id: multiplayer
playerCount: 4
startGameWhenReady: false
gameNetworkItem:gameNetwork
multiplayerView: matchmakingScene.mpView
maxJoinTries: 5
fewRoomsThreshold: 3
joinRankingIncrease: 200
enableLateJoin: true
appKey: "03df145d-0dac-46ab-aea2-79067d03dcd2"
pushKey:"93e69486-bc59-4d25-8109-778c107a2558"
onGameStarted: window.state = "game"
}
MenuScene {
id: menuScene
onMenuButtonPressed: {
console.log("PRESSED BUTTON "+ button)
switch (button){
case "game":
window.state = "game";
break;
case "matchmaking":
multiplayer.showMatchmaking()
window.state = "multiplayer";
break;
case "quick" :
multiplayer.joinOrCreateGame()
multiplayer.showMatchmaking()
window.state = "multiplayer";
break;
case "invites":
multiplayer.showInvitesList()
window.state = "multiplayer";
break;
case "inbox":
multiplayer.showInbox()
window.state = "multiplayer";
break;
case "friends":
multiplayer.showFriends()
window.state = "multiplayer";
break;
case "increase_score":
gameNetwork.reportRelativeScore(1)
break;
default :
window.state = button
}
}
}
GameScene {
id: gameScene
onBackButtonPressed: window.state = "menu"
}
MultiplayerScene {
id: matchmakingScene
onBackButtonPressed: window.state = "menu"
}
GameNetworkScene{
id: gameNetworkScene
onBackButtonPressed: window.state = "menu"
}
state: "menu"
activeScene: menuScene
states: [
State {
name: "menu"
PropertyChanges {target: menuScene; opacity: 1}
PropertyChanges {target: window; activeScene: menuScene}
},
State {
name: "game"
PropertyChanges {target: gameScene; opacity: 1}
PropertyChanges {target: window; activeScene: gameScene}
},
State {
name: "multiplayer"
PropertyChanges {target: matchmakingScene; opacity: 1}
PropertyChanges {target: window; activeScene: matchmakingScene}
},
State {
name: "gn"
PropertyChanges {target: gameNetworkScene; opacity: 1}
PropertyChanges {target: window; activeScene: gameNetworkScene}
}
]
Component.onDestruction: {
settings.counterAppInstances--