public void Update(GameTime gameTime) { if (GameMenu.IsMenuActive) { GameMenu.Update(); } else if (GameMenu.CharacterSelectionInProgress) // If we are in the process of selecting a character { this.NewGameSelection.Update(gameTime); Input.UpdateCharacterSelectionInput(); foreach (var character in AllCharacters) { character.Update(gameTime); } } else //Else we are playing the game { this.Camera.Update(gameTime, this.Character.Position); this.Levels[this.CurrentLevelIndex].Update(gameTime); if (this.Character.Health > 0 || (this.Character.DeathAnimation.FrameIndex < this.Character.DeathAnimation.Rectangles.Length && this.Character.DeathAnimation.IsActive)) { //If the character is alive and his death animation is playing we need to update it Input.UpdateInput(gameTime); this.Character.CheckCollisionOfCharacterWithItems(this.Levels[this.CurrentLevelIndex].ItemsOnTheField); this.Character.Update(gameTime); } } }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } // TODO: Add your update logic here KeyboardState state = Keyboard.GetState(); GameMode updatedGameMode = gameMode; if (updatedGameMode == GameMode.Menu) { updatedGameMode = gameMenu.Update(); } if (updatedGameMode == GameMode.HighScores) { updatedGameMode = highscores.Update(); } if (updatedGameMode == GameMode.CustomizeControls) { updatedGameMode = userControls.Update(); //gameLogic.UpdateGameControls(userControls.getUserControls()); } if (updatedGameMode == GameMode.Game) { if (gameMode != updatedGameMode) { gameLogic.startNewGame(); } gameLogic.Update(gameTime); } gameMode = updatedGameMode; previousState = state; base.Update(gameTime); }
public override void Update(GameTime gameTime) { _menu.Update(gameTime); }
protected override async void Update(GameTime gameTime) { if (IsActive) { switch (State) { case GameState.Started: { if (!Paused) { player.Update(gameTime); if (player.UpdateOccured) { world.UpdateBlocks(); } await world.UpdateAsync(); } gameMenu.Update(); break; } case GameState.Loading: { State = GameState.Started; currentSave = mainMenu.CurrentSave; time = new Time(currentSave.Parameters.Day, currentSave.Parameters.Hour, currentSave.Parameters.Minute); ScreenshotHandler screenshotHandler = new ScreenshotHandler(GraphicsDevice, Window.ClientBounds.Width, Window.ClientBounds.Height); BlockSelector blockSelector = new BlockSelector(GraphicsDevice); databaseHandler = new DatabaseHandler(this, currentSave.Parameters.SaveName); gameMenu = new GameMenu(this, GraphicsDevice, time, screenshotHandler, currentSave.Parameters); world = new WorldManager(gameMenu, databaseHandler, blockSelector, currentSave.Parameters); player = new Player(this, GraphicsDevice, currentSave.Parameters); renderer = new Renderer(this, GraphicsDevice, time, world.Region, screenshotHandler, blockSelector); world.SetPlayer(this, player, currentSave.Parameters); if (!File.Exists($@"Saves\{currentSave.Parameters.SaveName}\save_icon.png")) { player.Update(gameTime); world.Update(); renderer.Draw(world.ActiveChunks, player); screenshotHandler.SaveIcon(currentSave.Parameters.SaveName, out currentSave.Icon); } break; } case GameState.Exiting: { databaseHandler.Close(); player.SaveParameters(currentSave.Parameters); time.SaveParameters(currentSave.Parameters); currentSave.Parameters.Save(); player = null; world = null; databaseHandler = null; gameMenu = null; renderer = null; GC.Collect(); State = GameState.MainMenu; IsMouseVisible = true; break; } case GameState.MainMenu: { mainMenu.Update(); break; } } } base.Update(gameTime); }
/// <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) { // MONO: Add your update logic here //In every State you are able to quit if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { Exit(); } lastGameState = currentGameState; //MUSIC Updating Timer audioManager.UpdateAudioManagerTimer(gameTime); //Update Timer float animationFrameTime = 0.02f; float gameFrameTime = (float)gameTime.ElapsedGameTime.TotalSeconds; timeUntilNextFrame1 -= gameFrameTime; timeUntilNextFrame2 -= gameFrameTime; switch (currentGameState) { case GameState.SPLASHSCREEN: splashScreen.ClickedButton(); break; case GameState.MAINMENU: if (MediaPlayer.State != 0) { MediaPlayer.Stop(); turnOnMusic = true; } mainMenu.Update(this); this.IsMouseVisible = true; break; case GameState.LEVELEDITOR: levelEditor.HandleLevelEditorEvents(); levelEditor.moveOrDeletePlatforms(ref allGameObjectList, transformationMatrix); this.IsMouseVisible = true; levelEditor.moveCamera(ref cameraOffset); // Makes player movable in the leveleditor //Enemies are alive but not visible gameObjectsToRender = camera.GameObjectsToRender(wormPlayer.gameObjectPosition, allGameObjectList, ref interactiveObject); wormPlayer.Update(gameTime, gameObjectsToRender, ref viewableEnemies, interactiveObject, ref allGameObjectList, loadAndSave, ingameMenus, levelManager, ref allGameObjectList, shopKeeper, itemUIManager, ref hakume); break; case GameState.GAMELOOP: this.IsMouseVisible = false; //MUSIC if (turnOnMusic) { audioManager.Play("IngameMusic"); turnOnMusic = false; } //switch to LevelEditor levelManager.ManageLevels(wormPlayer.gameObjectPosition); itemUIManager.ManageItems(ref wormPlayer, ref levelObjectList); if (currentGameState == GameState.GAMELOOP) { //cameraOffset = new Vector2(0, 0); if (Keyboard.GetState().IsKeyDown(Keys.L) && !previousState.IsKeyDown(Keys.L)) { currentGameState = GameState.LEVELEDITOR; } //previousState = Keyboard.GetState(); if (Keyboard.GetState().IsKeyDown(Keys.M) && !previousState.IsKeyDown(Keys.M) && levelManager.currentLevel != Enums.Level.TUTORIAL) { currentGameState = GameState.MINIMAP; } if ((Keyboard.GetState().IsKeyDown(Keys.P) && !previousState.IsKeyDown(Keys.P)) || (GamePad.GetState(0).IsButtonDown(Buttons.Start) && !previousGamePadState.IsButtonDown(Buttons.Start))) { currentGameState = GameState.GAMEMENU; } previousState = Keyboard.GetState(); previousGamePadState = GamePad.GetState(0); } if (shopKeeper.shopOpen == true) { shopKeeper.handleShopKeeperEvents(); } if (timeUntilNextFrame1 <= 0) { gameObjectsToRender = camera.GameObjectsToRender(wormPlayer.gameObjectPosition, levelObjectList, ref interactiveObject); timeUntilNextFrame1 += animationFrameTime; } camera.SpawnEnemyOffScreen(wormPlayer, enemySpawnList, ref enemyList, enemySpriteSheets, levelManager.PlayerLevelLocation()); if (!camera.spawnBoss) { viewableEnemies = camera.RenderedEnemies(wormPlayer.gameObjectPosition, enemyList); } wormPlayer.Update(gameTime, gameObjectsToRender, ref viewableEnemies, interactiveObject, ref levelObjectList, loadAndSave, ingameMenus, levelManager, ref allGameObjectList, shopKeeper, itemUIManager, ref hakume); if (timeUntilNextFrame2 <= 0) { if (levelManager.PlayerLevelLocation() != Enums.Level.CROWN) { foreach (var enemy in viewableEnemies.ToList()) { enemy.Update(gameTime, gameObjectsToRender); if (enemy.EnemyAliveState() == false || enemy.fallOutOfMap) { viewableEnemies.RemoveAt(viewableEnemies.IndexOf(enemy)); } } } if (levelManager.PlayerLevelLocation() == Enums.Level.CROWN) { if (hakume != null) { hakume.Update(gameTime, gameObjectsToRender); } if (hakume.EnemyAliveState() == false) { hakume = null; } } timeUntilNextFrame2 += animationFrameTime; } break; case GameState.MINIMAP: if (Keyboard.GetState().IsKeyDown(Keys.M) && !previousState.IsKeyDown(Keys.M)) { currentGameState = GameState.GAMELOOP; } previousState = Keyboard.GetState(); break; case GameState.GAMEMENU: gameMenu.Update(this, loadAndSave); break; case GameState.CREDITS: credits.UpdateCredits(); break; } }
protected override void Initialize() { graphics.PreferredBackBufferWidth = 410; graphics.PreferredBackBufferHeight = 410; graphics.ApplyChanges(); this.IsMouseVisible = true; base.Initialize(); playerTurn = 1; gameCount = 0; currentGameState = gameStates.GAME_NOT_ON; gameMenu = new GameMenu(this); gameMenu.Update(); }