// ButtonJustPressed public override bool ButtonJustPressed(int button) { return(KeyboardStatePrevious.IsKeyUp((Keys)button) && KeyboardState.IsKeyDown((Keys)button)); }
protected override void Update(GameTime gameTime) { MouseState = Mouse.GetState(); cursorPos = new Vector2(MouseState.X, MouseState.Y); // cursor update KeyboardState = Keyboard.GetState(); // Allows the game to exit if (KeyboardState.IsKeyDown(Keys.Escape)) { this.Exit(); } switch (GameState) { case 0: // Video Intro if (videoPlayer.State != MediaState.Stopped) { videoTexture = videoPlayer.GetTexture(); } else { MediaPlayer.Play(inGameMusic); MediaPlayer.IsRepeating = true; GameState = 1; } break; case 1: // Game Started if (videoColor.A > 1) { videoColor.A -= 2; } // Checks for Pause if (KeyboardState.IsKeyDown(Keys.P) && KeyboardStatePrevious.IsKeyUp(Keys.P)) { MediaPlayer.Pause(); GameState = 2; } Player.Instance.Update(gameTime); MonstersHandler.Instance.Update(gameTime); DropHandler.Instance.Update(gameTime); ShotsHandler.Instance.UpdateShots(gameTime, KeyboardState); Toolbar.InventorySlots.Instance.Update(gameTime, MouseState); Toolbar.SystemMsg.Instance.GetLastMessages(); Toolbar.HP.Instance.Update(gameTime); InfoBoxes.Instance.Update(gameTime, MouseState); ElixirsHandler.Instance.Update(gameTime); // updates elixir reuse time Well.Instance.Update(gameTime); // updates well reuse time MarketDialogHandler.Instance.Update(MouseState, MouseStatePrevious); GameOverHandler.Instance.Update(gameTime); NpcHelperHandler.Update(gameTime); break; case 2: // Paused // Checks for Resume if (KeyboardState.IsKeyDown(Keys.P) && KeyboardStatePrevious.IsKeyUp(Keys.P)) { MediaPlayer.Resume(); GameState = 1; } Toolbar.HP.Instance.Update(gameTime); InfoBoxes.Instance.Update(gameTime, MouseState); MarketDialogHandler.Instance.Update(MouseState, MouseStatePrevious); break; case 3: // Game Over if (MediaPlayer.Queue.ActiveSong == inGameMusic) { MediaPlayer.Play(gameOverMusic); } InfoBoxes.Instance.Update(gameTime, MouseState); break; } this.KeyboardStatePrevious = KeyboardState; this.MouseStatePrevious = MouseState; base.Update(gameTime); }