public PauseItem(Vector2 initPos, string initText, SpriteFont sf, S_Pause.pauseOptions activeValue) { this.text = initText; // Recenter based on text: this.screenPos = initPos; this.screenPosCentered = CenterString.getCenterStringVector(initPos, this.text, sf); this.activeValue = activeValue; this.font = sf; }
// ** UPDATE ** public override void Update(GameTime gameTime, KeyboardState ks) { base.Update(gameTime, ks); // Update selection / glove position: // PRESS DOWN if (km.ActionPressed(KeyboardManager.action.down, this.playerWhoPaused)) { // SFX: parentManager.audioEngine.playSound(MGP_Constants.soundEffects.menuSelect, MGP_Constants.MENU_SFX_VOLUME); if (currentSelection < pauseItems.Count - 1) { currentSelection++; } else { currentSelection = 0; } // Update Glove pos: glove.pos = new Vector2(pauseItems[currentSelection].screenPosCentered.X - gloveAdjustX, pauseItems[currentSelection].screenPosCentered.Y - gloveAdjustY); } // PRESS UP if (km.ActionPressed(KeyboardManager.action.up, this.playerWhoPaused)) { // SFX: parentManager.audioEngine.playSound(MGP_Constants.soundEffects.menuSelect, MGP_Constants.MENU_SFX_VOLUME); if (currentSelection > 0) { currentSelection--; } else { currentSelection = pauseItems.Count - 1; } // Update Glove pos: glove.pos = new Vector2(pauseItems[currentSelection].screenPosCentered.X - gloveAdjustX, pauseItems[currentSelection].screenPosCentered.Y - gloveAdjustY); } // PRESS ENTER bool pressedResume = false; // false until proven true if (km.ActionPressed(KeyboardManager.action.select, this.playerWhoPaused)) { S_Pause.pauseOptions option = (S_Pause.pauseOptions)currentSelection; switch (option) { case S_Pause.pauseOptions.resume: pressedResume = true; break; case S_Pause.pauseOptions.viewBoard: State viewBoard = new S_CameraMode(parentManager, 0, 0, this); parentManager.AddStateQueue(viewBoard); break; case S_Pause.pauseOptions.quit: // update music: parentManager.audioEngine.setNextSong(MGP_Constants.music.mainMenu); parentManager.audioEngine.playNextSong(20, true); // Clear all states except audio engine and this state: List <State> statesToRemove = new List <State>(); foreach (State s in parentManager.states) { if (s != parentManager.audioEngine && s != this) { statesToRemove.Add(s); } } // Remove them: foreach (State s in statesToRemove) { parentManager.RemoveState(s); } // Delay the update of the gameStateManager: sendDelay = 2; parentManager.gameOptions = new GameOptions(); State newMenu = new S_MainMenu(parentManager, 0, 0); parentManager.AddStateQueue(newMenu); this.flagForDeletion = true; break; case S_Pause.pauseOptions.exitProgram: parentManager.game.Exit(); break; default: break; } } // UNPAUSE: if ((km.ActionPressed(KeyboardManager.action.pause, this.playerWhoPaused)) || (km.ActionPressed(KeyboardManager.action.cancel, this.playerWhoPaused)) || (pressedResume)) { Console.WriteLine("Player " + ((int)this.playerWhoPaused + 1).ToString() + " resumed the game"); // Unpause other states now: foreach (State s in statesToPause) { s.active = true; } // Turn music back up: parentManager.audioEngine.setMusicVolume(1.0f); // Destroy pause menu state flagForDeletion = true; sendDelay = 2; } // end UNPAUSE (if press pause/cancel button) }