/// <summary> /// Initializes a new VibrationManager. /// </summary> /// <param name="game"></param> public VibrationManager(Game game) : base(game) { // We only allow one manager per game if (instance != null) { throw new InvalidOperationException("Cannot create multiple VibrationManagers"); } // Store the manager instance instance = this; // Add a setting for each player vibrations.Add(PlayerIndex.One, new VibrationSettings()); vibrations.Add(PlayerIndex.Two, new VibrationSettings()); vibrations.Add(PlayerIndex.Three, new VibrationSettings()); vibrations.Add(PlayerIndex.Four, new VibrationSettings()); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Update our input state gamePadPrev = gamePad; keyboardPrev = keyboard; gamePad = GamePad.GetState(PlayerIndex.One); keyboard = Keyboard.GetState(); // Allows the game to exit if (gamePad.Buttons.Back == ButtonState.Pressed || keyboard.IsKeyDown(Keys.Escape)) { this.Exit(); } bool shake = false; bool longShake = false; // Check for the A button/key for a short shake if ((gamePad.IsButtonDown(Buttons.A) && gamePadPrev.IsButtonUp(Buttons.A)) || (keyboard.IsKeyDown(Keys.A) && keyboardPrev.IsKeyUp(Keys.A))) { shake = true; } // Check for the X button/key for a long shake if ((gamePad.IsButtonDown(Buttons.X) && gamePadPrev.IsButtonUp(Buttons.X)) || (keyboard.IsKeyDown(Keys.X) && keyboardPrev.IsKeyUp(Keys.X))) { longShake = true; } // Read all gestures while (TouchPanel.IsGestureAvailable) { GestureSample gesture = TouchPanel.ReadGesture(); // Taps generate a short shake if (gesture.GestureType == GestureType.Tap) { shake = true; } // Double taps generate a long shake else if (gesture.GestureType == GestureType.DoubleTap) { longShake = true; } } // If we're performing a long shake, call the Shake method with a 2 second length if (longShake) { camera.Shake(25f, 2f); VibrationManager.Vibrate(PlayerIndex.One, .5f, .5f, 2f); } // If we're performing a short shake, call the Shake method with a .4 second length else if (shake) { camera.Shake(25f, .4f); VibrationManager.Vibrate(PlayerIndex.One, .5f, .5f, .4f); } // Update our camera camera.Update(gameTime); base.Update(gameTime); }