/// <summary> /// /// </summary> private void _GameWin() { AudioPlayer.Stop(); TimeSpan span = AudioPlayer.PlayWin(); _isGameFinished = true; _gameOverTimer.Interval = span.TotalMilliseconds; _gameOverTimer.Enabled = true; }
/// <summary> /// /// </summary> private void _GameOver() { AudioPlayer.Stop(); TimeSpan span = AudioPlayer.PlayBomb(); // Show game over screen and stop the game GameState.CurrentState = State.GameOver; _gameOverTimer.Interval = span.TotalMilliseconds; _gameOverTimer.Enabled = true; }
/// <summary> /// /// </summary> /// <param name="gameTime"></param> private void _UpdateGame(GameTime gameTime) { _PauseGameIfNeeded(); _controller.Update(gameTime, _keyboardState); if (!_gameSoudStarted) { AudioPlayer.Stop(); AudioPlayer.PlayGame(); } _menuSoudStarted = false; _gameSoudStarted = true; }
/// <summary> /// /// </summary> /// <param name="gameTime"></param> private void _UpdateMenu(GameTime gameTime) { _mouseCursor.UpdateMouse(_menu); _menu.Update(_keyboardState, _mouseCursor); var _mouseState = Mouse.GetState(); // Update keys. if (_keyboardState.IsKeyDown(Keys.Enter) || (_mouseState.LeftButton == ButtonState.Pressed && _menu.GetMenuItemIntersectedByMouse(_mouseCursor) != -1)) { if (_menu.SelectedItem == (int)MenuState.Start) { _controller.GameState.CurrentState = State.Game; _controller.Initialize(); base.Initialize(); } else if (_menu.SelectedItem == (int)MenuState.Exit) { this.Exit(); } else if (_menu.SelectedItem == (int)MenuState.Hits) { _controller.GameState.CurrentState = State.Hits; } } else if (_mouseState.LeftButton == ButtonState.Pressed) { int clickedLevel = _menu.GetVolumeItemIntersectedByMouse(_mouseCursor); if (clickedLevel > -1) { _menu.VolumeLevel = clickedLevel; AudioPlayer.Volume = clickedLevel * 0.2f; } } // Update audio for Start application (menu start): it should play only once, // so we need to find exact time where we can start. if (GameHelper.IsItNearValues(gameTime.TotalGameTime, _span) && !_menuSoudStarted) { AudioPlayer.Stop(); AudioPlayer.PlayMenu(); _menuSoudStarted = true; } }
/// <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) { // Allows the game to exit _keyboardState = Keyboard.GetState(); // Catch keys in menu. if (_controller.GameState.CurrentState == State.Menu) { _UpdateMenu(gameTime); _gameSoudStarted = false; } else if (_controller.GameState.CurrentState == State.Game) { _UpdateGame(gameTime); if (_keyboardState.IsKeyDown(Keys.Escape) && !_controller.IsGameFinished) { AudioPlayer.Stop(); AudioPlayer.PlayMenu(); _controller.GameState.CurrentState = State.UserInput; } else if (_keyboardState.IsKeyDown(Keys.Up)) { _controller.SpeedUp(); } else if (_keyboardState.IsKeyUp(Keys.Up)) { _controller.SlowDown(); } } else if (_controller.GameState.CurrentState == State.Paused) { _PauseGameIfNeeded(); } else if (_controller.GameState.CurrentState == State.Hits) { _hitList.Update(_keyboardState); if (_keyboardState.IsKeyDown(Keys.Escape)) { _controller.GameState.CurrentState = State.Menu; } } else if (_controller.GameState.CurrentState == State.UserInput) { _userInput.Update(_keyboardState); if (_userInput.IsInputFinished) { string userName = _userInput.UserName; string score = _userInput.Score; _hitList.AddUserData(new UserData() { Score = score, UserName = userName, CreationTime = DateTime.Now }); _controller.GameState.CurrentState = State.Hits; } } else { // Do nothing. } base.Update(gameTime); }