update the first three states before trying sth different

This commit is contained in:
Chauntalle Schüle 2020-05-31 22:03:35 +02:00
parent 3ea48c399e
commit f4847e79d7
6 changed files with 29 additions and 6 deletions

View File

@ -51,6 +51,7 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
override init() {
super.init()
// StateManager.stateManager.changeState(wantedState: .syncingSt, menuSc: nil, gameVC: nil)
localPlayer.register(self)
authUser();
localPlayerRandomNumber = RandomNumber()
@ -182,8 +183,8 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
self.gameScene = scene
sendStateToPeers(state: State(state: 2))
os_log("State 2 wurde an Host gesendet", log: LOG, type: .info)
initIsFinish = true
os_log("Peer startet Spiel", log: LOG, type: .info)
// initIsFinish = true
// os_log("Peer startet Spiel", log: LOG, type: .info)
}
MultiplayerNetwork.sharedInstance.isSending = false
}
@ -239,6 +240,7 @@ final class GameCenterManager: NSObject, GKMatchmakerViewControllerDelegate, GKG
}
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
StateManager.stateManager.changeState(wantedState: .syncingSt, menuSc: menusc, gameVC: nil)
viewController.dismiss(animated: true, completion: nil)
myMatch = match
if !isMatchStarted && match.expectedPlayerCount == 0 {

View File

@ -72,7 +72,10 @@ class GameScene: SKScene{
}
override func update(_ currentTime: TimeInterval) {
entityManager.getBackground()?.update(deltaTime: currentTime)
StateManager.stateManager.stateMachine!.update(deltaTime: currentTime)
/* entityManager.getBackground()?.update(deltaTime: currentTime)
entityManager.getHUD()?.component(ofType: TimerComponent.self)?.update()
*/
}
func addBaseDetails(touchLocation: CGPoint, spriteNode: SKNode?, touches: Set<UITouch>, event: UIEvent?, entity: GKEntity){

View File

@ -29,7 +29,6 @@ class MenuScene: SKScene {
SoundManager.sharedInstance.stopMenuMusic()
} else {
if GameCenterManager.isAuthenticated {
StateManager.stateManager.changeState(wantedState: .syncingSt, menuSc: self, gameVC: nil)
GameCenterManager.sharedInstance.presentMatchmaker()
}else {
GameCenterManager.sharedInstance.authUser()

View File

@ -19,10 +19,14 @@ class GameState: GKState {
override func didEnter(from previousState: GKState?) {
os_log("Entered Game State", log: LOG, type: .info)
if CommandLine.arguments.contains("--no-matchmaking") {
StateManager.stateManager.menuSc!.loadScene(scene: GameScene(size: StateManager.stateManager.menuSc!.size))
}
}
override func update(deltaTime seconds: TimeInterval) {
EntityManager.gameEMInstance.getBackground()?.update(deltaTime: seconds)
EntityManager.gameEMInstance.getHUD()?.component(ofType: TimerComponent.self)?.update()
}
override func willExit(to nextState: GKState) {

View File

@ -22,8 +22,8 @@ class MenuState: GKState {
}
override func update(deltaTime seconds: TimeInterval) {
if menuEM.entities.count != 0 {
menuEM.getBackground()!.update(deltaTime: seconds)
if menuEM.entities.count != 0 {
menuEM.getBackground()!.update(deltaTime: seconds)
menuEM.getButtonByName(buttonName: "startGameButton").component(ofType: ButtonComponent.self)?.buttonNode.isEnabled = GameCenterManager.isAuthenticated
}

View File

@ -10,7 +10,10 @@ import GameKit
import os
class SyncingState: GKState {
let LOG = OSLog.init(subsystem: "SyncingState", category: "SyncingState")
var menuEM = EntityManager.menuEMInstance
var previousState: GKState?
override func isValidNextState(_ stateClass: AnyClass) -> Bool {
return stateClass is GameState.Type || stateClass is EndGameState.Type
@ -18,8 +21,20 @@ class SyncingState: GKState {
override func didEnter(from previousState: GKState?) {
os_log("Entered Syncing State", log: LOG, type: .info)
self.previousState = previousState
}
override func update(deltaTime seconds: TimeInterval) {
if previousState is MenuState {
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.changeState(wantedState: .gameSt, menuSc: self, gameVC: nil)
}
}
}
override func willExit(to nextState: GKState) {
}