protected override void Update(GameTime gameTime) { mouseState = Mouse.GetState(); keyboardState = Keyboard.GetState(); switch (CurrentGameState) { case GameState.EscMenu: case GameState.Menu: menu.Update(gameTime, this, mouseState, lastMouseState, keyboardState, lastKeyboardState); Window.Title = mouseState.X + " : " + mouseState.Y; break; case GameState.Playing: playing.Update(gameTime, keyboardState, lastKeyboardState, mouseState, lastMouseState, this); break; case GameState.Loading: loading.Update(gameTime, this); Window.Title = mouseState.X + " : " + mouseState.Y; break; case GameState.TitleScreen: titleScreen.Update(gameTime, this, mouseState, keyboardState); Window.Title = mouseState.X + " : " + mouseState.Y; break; } lastKeyboardState = keyboardState; lastMouseState = mouseState; base.Update(gameTime); }
public void Update(GameTime gameTime, Game1 game1, MouseState mouseState, KeyboardState keyboardState) { if (gameTime.TotalGameTime.TotalMilliseconds >= LoadingTime - 500) { if (counter < TimeSpan.FromMilliseconds(1000)) { counter += gameTime.ElapsedGameTime; } if (counter > TimeSpan.FromMilliseconds(1000)) { if (isAdding) { PressAlpha += (int)gameTime.ElapsedGameTime.TotalMilliseconds / 2; } else { PressAlpha -= (int)gameTime.ElapsedGameTime.TotalMilliseconds / 2; } if (PressAlpha > 255 | PressAlpha < 0) { if (!isAdding) { counter = TimeSpan.Zero; } isAdding = !isAdding; } } } if (gameTime.TotalGameTime.TotalMilliseconds < LoadingTime) { loading.Update(gameTime, game1); } if (!(timePressed.TotalMilliseconds < DummyTimeSpan.TotalMilliseconds) && gameTime.TotalGameTime.TotalMilliseconds >= LoadingTime + TimeBeforeUserCanContinue && (keyboardState.GetPressedKeys().Length > 0 || mouseState.LeftButton == ButtonState.Pressed)) { timePressed = gameTime.TotalGameTime; Game1.PlaySound("back"); } if (gameTime.TotalGameTime.TotalMilliseconds - timePressed.TotalMilliseconds >= TimeToWaitAfterPressed) { isGoingToMenu = true; } if (isGoingToMenu) { logoAnimation += gameTime.ElapsedGameTime; if (logoAnimation.TotalMilliseconds >= timeBeforeMoving + logoMoveTime + timeAfterAnimation) { game1.ChangeGameState(GameState.Menu); // animation finished } } }