/************************************* * Check menu input *************************************/ private void checkMenuInput(MenuGUI gui_menu) { KeyboardState newState = Keyboard.GetState(); // Is Enter key pressed if (newState.IsKeyDown(Keys.Enter)) { // If not down last update, key has just been pressed. if (!oldState.IsKeyDown(Keys.Enter)) { if (gui_menu.getActiveItem() == 1) { if (gamePaused == true) { playingInstance.Play(); gamePaused = false; } else { startNewGame(); } } else if (gui_menu.getActiveItem() == 2) { if (currentGameState == GameState.GameEnded || gamePaused == true) { titleInstance.Play(); gamePaused = false; currentGameState = GameState.MainMenu; } else if (currentGameState == GameState.GameStarted && game.gameOver == true) { titleInstance.Play(); game.gameOver = false; currentGameState = GameState.MainMenu; } else { this.Exit(); } } } } // Is Down key pressed if (newState.IsKeyDown(Keys.Down)) { // If not down last update, key has just been pressed. if (!oldState.IsKeyDown(Keys.Down)) { gui_menu.activeItemDown(); } } // Is Up key pressed if (newState.IsKeyDown(Keys.Up)) { // If not down last update, key has just been pressed. if (!oldState.IsKeyDown(Keys.Up)) { gui_menu.activeItemUp(); } } // Set oldState oldState = newState; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here splashTexture = this.Content.Load<Texture2D>("splash"); font = Content.Load<SpriteFont>("fontTexture"); titleMusic = Content.Load<SoundEffect>("titleMusic"); titleInstance = titleMusic.CreateInstance(); titleInstance.IsLooped = true; doorEffect = Content.Load<SoundEffect>("door"); doorInstance = doorEffect.CreateInstance(); doorInstance.Pitch = 1f; doorInstance.Volume = .5f; dummyTexture = new Texture2D(graphics.GraphicsDevice, 1, 1); dummyTexture.SetData(new Color[] { Color.White }); // New Camera camera = new View.Camera(graphics.GraphicsDevice.Viewport); //Load MenuGUI for mainMenu gui_mainMenu = new MenuGUI(spriteBatch, Content, camera.getScreenWidth() / 5, camera.getScreenHeight() - camera.getScreenHeight() / 4); gui_mainMenu.addItem("New Game"); gui_mainMenu.addItem("Exit"); //Load menuGUI for pauseMenu gui_pauseMenu = new MenuGUI(spriteBatch, Content, camera.getScreenWidth() / 2, camera.getScreenHeight() / 3 + 40); gui_pauseMenu.addItem("Continue"); gui_pauseMenu.addItem("Exit to main Menu"); //Load menuGUI for gameDoneMenu gui_gameDoneMenu = new MenuGUI(spriteBatch, Content, camera.getScreenWidth() / 2, camera.getScreenHeight() / 3 + 40); gui_gameDoneMenu.addItem("New Game"); gui_gameDoneMenu.addItem("Exit to main Menu"); }