/// <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) { currentKeyboardState = Keyboard.GetState(); if (currentKeyboardState.IsKeyDown(Keys.Escape)) { this.Exit(); } if (currentGameState == GameState.StartMenu) { if (currentKeyboardState.IsKeyDown(Keys.Space) && !oldKeyboardState.IsKeyDown(Keys.Space)) { currentGameState = GameState.Running; } } else if (currentGameState == GameState.LevelCompleted && levelHandler.CurrentLevelId == 5) { currentGameState = GameState.Completed; } else if (currentGameState == GameState.LevelCompleted || currentGameState == GameState.LevelFailed && currentKeyboardState.IsKeyDown(Keys.Space) && !oldKeyboardState.IsKeyDown(Keys.Space)) { if (currentGameState == GameState.LevelCompleted) { levelHandler.CurrentLevelId += 1; } levelHandler.InitializeLevel(); lava.Initialize(); player.Initialize(); player.CurrentLevel = levelHandler.CurrentLevel; currentGameState = GameState.StartMenu; } if (currentGameState == GameState.Running) { if (player.Y - lava.TopPosition.Y > 100) { currentGameState = GameState.LevelFailed; } if (player.Y > -110) { player.Update(gameTime, currentKeyboardState, oldKeyboardState); } else { currentGameState = GameState.LevelCompleted; } } if (currentGameState != GameState.StartMenu) { lava.Update(gameTime); } oldKeyboardState = currentKeyboardState; base.Update(gameTime); }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } if (currentGameState == GameState.StartMenu) { tc = TouchPanel.GetState(); if (tc.Count > 0) { foreach (TouchLocation tl in tc) { if (tl.Position != oldTouchPosition) { oldTouchPosition = tl.Position; currentGameState = GameState.Running; } } } } else if (currentGameState == GameState.LevelCompleted && levelHandler.CurrentLevelId == 5) { currentGameState = GameState.Completed; if (!scoreSaved) { saveScoreThread = new Thread(SaveScoreThread); saveScoreThread.Start(); } ScoreHandler.LoadScore(deviceId, totalTime); } else if (currentGameState == GameState.LevelCompleted || currentGameState == GameState.LevelFailed) { tc = TouchPanel.GetState(); if (tc.Count > 0) { foreach (TouchLocation tl in tc) { if (tl.Position != oldTouchPosition) { oldTouchPosition = tl.Position; if (currentGameState == GameState.LevelCompleted) { levelHandler.CurrentLevelId += 1; } levelHandler.InitializeLevel(); lava.Initialize(); player.Initialize(); player.CurrentLevel = levelHandler.CurrentLevel; currentGameState = GameState.StartMenu; } } } } if (currentGameState == GameState.Running) { totalTime += (float)gameTime.ElapsedGameTime.TotalSeconds; if (player.Y - lava.TopPosition.Y > 100) { currentGameState = GameState.LevelFailed; } if (player.Y > -110) { player.Update(TargetElapsedTime); } else { currentGameState = GameState.LevelCompleted; } } if (currentGameState != GameState.StartMenu) { lava.Update(TargetElapsedTime); } base.Update(gameTime); }