private void DetectSelection(GameState gameState) { int x = Mouse.GetState().Position.X; int y = Mouse.GetState().Position.Y; isButtonSelected[0] = (gameState.Equals(GameState.Menu) && x > newGameFrame.Left && x < newGameFrame.Right) && (y > newGameFrame.Top && y < newGameFrame.Bottom); isButtonSelected[1] = ((gameState.Equals(GameState.Menu) || gameState.Equals(GameState.Pause) || gameState.Equals(GameState.GameOver)) && x > quitFrame.Left && x < quitFrame.Right) && (y > quitFrame.Top && y < quitFrame.Bottom); isButtonSelected[2] = ((gameState.Equals(GameState.Pause) || gameState.Equals(GameState.GameOver)) && x > quitToMenuFrame.Left && x < quitToMenuFrame.Right) && (y > quitToMenuFrame.Top && y < quitToMenuFrame.Bottom); isButtonSelected[3] = (gameState.Equals(GameState.Pause) && x > resumeFrame.Left && x < resumeFrame.Right) && (y > resumeFrame.Top && y < resumeFrame.Bottom); isButtonSelected[4] = (gameState.Equals(GameState.Menu) && x > authorsFrame.Left && x < authorsFrame.Right) && (y > authorsFrame.Top && y < authorsFrame.Bottom); }
public GameState Update(GameState gameState, Game1 game, GameTime gameTime) { currentState = Keyboard.GetState(); if (isSelectingKeypad) { gameState = GameState.Keypad; } if (gameState.Equals(GameState.Intro)) { isIntro = true; introTimer += (float)gameTime.ElapsedGameTime.TotalSeconds; introShader.Parameters["IntroTime"].SetValue(introTimer); if (introTimer >= introTime) { gameState = GameState.Menu; } } else if (gameState.Equals(GameState.Menu)) { if (!isMenu) { isMenu = true; } if (isIntro) { isIntro = false; } if (isCredits) { isCredits = false; } if (isPauseMenu) { isPauseMenu = false; } if (isGameOverMenu) { isGameOverMenu = false; } if (isSelectingKeypad) { isSelectingKeypad = false; } creditsPositionY = game.Window.ClientBounds.Height * 0.875f; DetectSelection(gameState); ChangeFrame(); DetectClick(ref gameState, game); } else if (gameState.Equals(GameState.NewGame)) { game.InitializeGame(); game.LoadGame(); gameState = GameState.Game; } else if (gameState.Equals(GameState.Game)) { if (isMenu) { isMenu = false; } if (isPauseMenu) { isPauseMenu = false; } if (currentState.IsKeyDown(Keys.Escape) && oldState.IsKeyUp(Keys.Escape)) { gameState = GameState.Pause; } if (game.PlayerHealth <= 0.0f) { gameState = GameState.GameOver; } } else if (gameState.Equals(GameState.Pause)) { if (!isPauseMenu) { isPauseMenu = true; } if (currentState.IsKeyDown(Keys.Escape) && oldState.IsKeyUp(Keys.Escape)) { gameState = GameState.Game; } DetectSelection(gameState); ChangeFrame(); DetectClick(ref gameState, game); } else if (gameState.Equals(GameState.Keypad)) { if (currentState.IsKeyDown(Keys.Escape) && oldState.IsKeyUp(Keys.Escape)) { isSelectingKeypad = false; gameState = GameState.Game; } DetectKeypad(ref gameState, game); } else if (gameState.Equals(GameState.GameOver)) { isGameOverMenu = true; DetectSelection(gameState); ChangeFrame(); DetectClick(ref gameState, game); } else if (gameState.Equals(GameState.Credits)) { isMenu = false; isCredits = true; if (currentState.IsKeyDown(Keys.Escape) && oldState.IsKeyUp(Keys.Escape)) { gameState = GameState.Menu; } if (creditsPositionY <= -creditsTexture.Height * 0.4875f) { gameState = GameState.Menu; } } oldState = currentState; return(gameState); }