/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { LogCat.beginProfiling("Update"); lastGameTime = gameTime; // Let's start out looking at our list runPackageList(); HandleInput(); // This method will make sure everyone has an XBox id CheckPlayerCount(); LogCat.updateValue("Players", "" + numberOfPlayers); // This should only happen in the beginning if (currentScene == null) { LogCat.addValue("Scene", "Null"); switchScene(); } else { } if (currentState == state.enteringScene || currentState == state.inScene) { // All things in milliseconds currentScene.Update(gameTime.ElapsedGameTime.Milliseconds / TimeScale); currentState = state.inScene; if (currentScene.ReadyToExit) { currentState = state.leavingScene; } else { } } else if (currentState == state.leavingScene) { // Set up the next scene based on the events of the previous screen nextSceneEnum = currentScene.GetNextScene(); switchScene(); } else { } InputManager.FlushInput(); base.Update(gameTime); LogCat.endProfiling("Update"); }
private void switchScene() { Scene nextScene = null; switch (nextSceneEnum) { case sceneEnum.CreditsScene: nextScene = new CreditsScene(); break; case sceneEnum.GameScene: nextScene = new GameScene(); break; case sceneEnum.LoadingScene: nextScene = new LoadingScene(); break; case sceneEnum.LobbyScene: nextScene = new LobbyScene(); break; case sceneEnum.LogoScene: nextScene = new LogoScene(); break; case sceneEnum.MainMenuScene: nextScene = new MainMenuScene(); break; case sceneEnum.MissionSelectScene: nextScene = new MissionSelectScene(); break; case sceneEnum.OptionsScene: nextScene = new OptionsScene(); break; case sceneEnum.PlayerSelectScene: nextScene = new PlayerSelectScene(); break; case sceneEnum.StartScene: nextScene = new StartScene(); break; } if (currentScene != null) { currentScene.Exit(nextScene); } else { } currentScene = nextScene; currentSceneEnum = nextSceneEnum; currentScene.Initialize(); currentState = state.enteringScene; foreach (Player player in localPlayers) { player.setPlayerCamera(currentScene); updatePlayerCameras(); } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { currentState = state.enteringScene; nextSceneEnum = sceneEnum.LogoScene; currentSceneEnum = sceneEnum.LogoScene; packageList = new Stack<Package>(); LuaManager.Initialize(); InputManager.Initialize(); LogCat.Initialize(); ContentLoadManager.Initialize(); ProjectileManager.Initialize(); SoundManager.Initialize(); packetWriter = new PacketWriter(); packetReader = new PacketReader(); localPlayers = new List<Player>(); controllers = new Player[MAX_CONTROLLERS]; controllers[0] = new Player(Player.ControllerIndex.One); controllers[1] = new Player(Player.ControllerIndex.Two); controllers[2] = new Player(Player.ControllerIndex.Three); controllers[3] = new Player(Player.ControllerIndex.Four); controllers[4] = new Player(Player.ControllerIndex.Keyboard); base.Initialize(); }