Niko Jochim 9329978981 * create new GameCenterManager
* send RandomNumber to all Peers Method
2020-05-27 20:41:05 +00:00

71 lines
3.0 KiB
Swift

//
// MenuScene.swift
// GoldWars
//
// Created by Aldin Duraki on 18.04.20.
// Copyright © 2020 SP2. All rights reserved.
//
import SpriteKit
import SceneKit
class MenuScene: SKScene {
var entityManager = EntityManager.menuEMInstance
override func sceneDidLoad() {
GameCenterManager.sharedInstance.menusc = self
entityManager.setScene(scene: self)
let midX = self.size.width / 2
let midY = self.size.height / 2
entityManager.add(Button(name: "startGameButton",
textureName: "yellow_button04",
text: "Start Game",
position: CGPoint(x: midX, y: midY),
onButtonPress: {
if CommandLine.arguments.contains("--no-matchmaking") {
self.loadScene(scene: GameScene(size: self.size))
SoundManager.sharedInstance.stopMenuMusic()
} else {
if GameCenterManager.isAuthenticated {
GameCenterManager.sharedInstance.presentMatchmaker()
}else {
GameCenterManager.sharedInstance.authUser()
}
}
}))
entityManager.add(Button(name: "settingsButton",
textureName: "yellow_button04",
text: "Settings",
position: CGPoint(x: midX, y: midY - 80 ),
onButtonPress: {
let scene = SettingsScene(size: self.size)
self.loadScene(scene: scene)
}))
entityManager.add(Background(size: self.size))
entityManager.add(SpinningLogoEntity(position: CGPoint(x: midX, y: midY + 200)))
if SoundManager.sharedInstance.isMusicPlaying == false && SoundManager.sharedInstance.isMusicEnabled == true {
SoundManager.sharedInstance.startMenuMusic()
}
}
func loadScene(scene: SKScene) {
let transition = SKTransition.flipVertical(withDuration: 0.5)
entityManager.entities.removeAll()
self.view?.presentScene(scene, transition: transition)
}
override func update(_ currentTime: TimeInterval) {
if entityManager.entities.count != 0 {
entityManager.getBackground()!.update(deltaTime: currentTime)
entityManager.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterManager.isAuthenticated
}
if GameCenterManager.sharedInstance.initIsFinish {
self.loadScene(scene: GameCenterManager.sharedInstance.gameScene!)
}
}
}