game scene and menu scene are now initialized in states, still need to test for 2 player

This commit is contained in:
Chauntalle Schüle 2020-05-29 13:04:40 +02:00
parent 0296edb080
commit 8537dee231
4 changed files with 37 additions and 16 deletions

View File

@ -19,8 +19,9 @@ class GameState: GKState {
override func didEnter(from previousState: GKState?) {
os_log("Entered Game State", log: LOG, type: .info)
StateManager.stateManager.menuSc!.loadScene(scene: GameScene(size: StateManager.stateManager.menuSc!.size))
}
override func update(deltaTime seconds: TimeInterval) {
}

View File

@ -15,19 +15,8 @@ class GameViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
StateManager.stateManager.wantedState = StateTypes.menuSt
StateManager.stateManager.createStates()
StateManager.stateManager.enterState()
if let view = self.view as! SKView? {
let scene = MenuScene(size: self.view.bounds.size)
EntityManager.menuEMInstance.setScene(scene: scene)
scene.scaleMode = .aspectFill
view.presentScene(scene)
//TODO: create dev profile or remove on delivery
view.showsFPS = true
view.showsNodeCount = true
}
StateManager.stateManager.changeState(wantedState: .menuSt, menuSc: nil, gameVC: self)
GameCenterManager.sharedInstance.viewController = self
}

View File

@ -12,18 +12,46 @@ import os
class MenuState: GKState {
let LOG = OSLog.init(subsystem: "MenuState", category: "MenuState")
var menuEM = EntityManager.menuEMInstance
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
if CommandLine.arguments.contains("--no-matchmaking") {
return stateClass is GameState.Type
}
return stateClass is SyncingState.Type
}
override func update(deltaTime seconds: TimeInterval) {
/* if menuEM.entities.count != 0 {
menuEM.getBackground()!.update(deltaTime: seconds)
menuEM.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterManager.isAuthenticated
}
if GameCenterManager.sharedInstance.initIsFinish {
StateManager.stateManager.menuSc!.loadScene(scene: GameCenterManager.sharedInstance.gameScene!)
}*/
}
override func didEnter(from previousState: GKState?) {
os_log("Entered Menu State", log: LOG, type: .info)
if (previousState == nil){
presentFirstViewMenu()
}
}
override func willExit(to nextState: GKState) {
}
func presentFirstViewMenu(){
if let view = StateManager.stateManager.gameVC!.view as! SKView? {
let scene = MenuScene(size: StateManager.stateManager.gameVC!.view.bounds.size)
EntityManager.menuEMInstance.setScene(scene: scene)
scene.scaleMode = .aspectFill
view.presentScene(scene)
//TODO: create dev profile or remove on delivery
view.showsFPS = true
view.showsNodeCount = true
}
}
}

View File

@ -8,6 +8,7 @@
import SpriteKit
import SceneKit
class MenuScene: SKScene {
var entityManager = EntityManager.menuEMInstance
@ -23,12 +24,13 @@ class MenuScene: SKScene {
position: CGPoint(x: midX, y: midY),
onButtonPress: {
if CommandLine.arguments.contains("--no-matchmaking") {
self.loadScene(scene: GameScene(size: self.size))
StateManager.stateManager.changeState(wantedState: .gameSt, menuSc: self, gameVC: nil)
//self.loadScene(scene: GameScene(size: self.size))
SoundManager.sharedInstance.stopMenuMusic()
} else {
if GameCenterManager.isAuthenticated {
GameCenterManager.sharedInstance.presentMatchmaker()
StateManager.stateManager.changeState(wantedState: .syncingSt, menuSc: self, gameVC: nil)
GameCenterManager.sharedInstance.presentMatchmaker()
}else {
GameCenterManager.sharedInstance.authUser()
}
@ -78,4 +80,5 @@ class MenuScene: SKScene {
}
}
}