public void Update(GameTime gameTime) { if (ActiveScene.GetType().Name == "MenuScene") { MenuItemSprite s = ActiveScene.AllTheSpritesWithinTheScene.OfType <MenuItemSprite>().FirstOrDefault(x => x.Bounds.Contains(InputEngine.MousePosition) && InputEngine.IsMouseLeftClick()); if (s != null) { if (s.SpriteID == "MI1") { PreviousScene = ActiveScene; ActiveScene = AllScenes.Pop(); AllScenes.Push(PreviousScene); } else if (s.SpriteID == "MI2") { PreviousScene = ActiveScene; ActiveScene = CreateHighscoreScene(); AllScenes.Push(PreviousScene); } else if (s.SpriteID == "MI3") { Helper.CurrentGame.Exit(); } } } else if (InputEngine.IsKeyPressed(ChangeSceneKey)) { if (ActiveScene.GetType().Name == "PlayScene") { PreviousScene = ActiveScene; ActiveScene = AllScenes.Pop(); AllScenes.Push(PreviousScene); } else if (ActiveScene.GetType().Name == "HighscoreScene") { ActiveScene = AllScenes.Pop(); } } if (ActiveScene.GetType().Name == "PlayScene") { ActiveScene.Update(gameTime); PlayScene playScene = (PlayScene)ActiveScene; if (playScene.Gameover) { ActiveScene = CreateHighscoreScene(); } } }
/// <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> override public void Update(GameTime gameTime) { switch (gameState.currentState)//Handle updates for each scene seperately. { case State.MAIN_MENU: if (ActiveScene.GetType() != typeof(MainMenu)) //If the scene state has change begin the load to the correct scene { gameState.loadNewScene(); } break; case State.CAR_BUILDER: if (ActiveScene.GetType() != typeof(CarBuilder)) { gameState.loadNewScene(); } break; case State.GAME: if (ActiveScene.GetType() != typeof(CarGame)) { gameState.loadNewScene(); } else if (((CarGame)gameState.currentScene).gm.isGameOver() && gameState.requestedChangeState) { gameState.loadNewScene(); } else { ((CarGame)gameState.currentScene).doUpdate(); } break; } if (Managers.GameInput.IsKeyDown(GeonBit.Input.GameKeys.Escape) || gameState.quitFlag)//Escape to quit from any scene { Exit(); } }