/// <summary> /// Handle all the input. /// </summary> /// <param name="input"></param> public override void HandleInput(InputState input) { if (input == null) { throw new ArgumentNullException("input"); } // Rotate the maze according to accelerometer data Vector3 currentAccelerometerState = Accelerometer.GetState().Acceleration; if (Microsoft.Devices.Environment.DeviceType == DeviceType.Device) { //Change the velocity according to acceleration reading maze.Rotation.Z = (float)Math.Round(MathHelper.ToRadians(currentAccelerometerState.Y * 30), 2); maze.Rotation.X = -(float)Math.Round(MathHelper.ToRadians(currentAccelerometerState.X * 30), 2); } else if (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator) { Vector3 Rotation = Vector3.Zero; if (currentAccelerometerState.X != 0) { if (currentAccelerometerState.X > 0) { Rotation += new Vector3(0, 0, -angularVelocity); } else { Rotation += new Vector3(0, 0, angularVelocity); } } if (currentAccelerometerState.Y != 0) { if (currentAccelerometerState.Y > 0) { Rotation += new Vector3(-angularVelocity, 0, 0); } else { Rotation += new Vector3(angularVelocity, 0, 0); } } // Limit the rotation of the maze to 30 degrees maze.Rotation.X = MathHelper.Clamp(maze.Rotation.X + Rotation.X, MathHelper.ToRadians(-30), MathHelper.ToRadians(30)); maze.Rotation.Z = MathHelper.Clamp(maze.Rotation.Z + Rotation.Z, MathHelper.ToRadians(-30), MathHelper.ToRadians(30)); } }
/// <summary> /// Handle all the input. /// </summary> /// <param name="input"></param> public override void HandleInput(InputState input) { if (input == null) { throw new ArgumentNullException("input"); } if (input.IsPauseGame(null)) { if (!gameOver) { PauseCurrentGame(); } else { FinishCurrentGame(); } } if (IsActive && !startScreen) { if (input.Gestures.Count > 0) { GestureSample sample = input.Gestures[0]; if (sample.GestureType == GestureType.Tap) { if (gameOver) { FinishCurrentGame(); } } } if (!gameOver) { if (Microsoft.Devices.Environment.DeviceType == DeviceType.Device) { // Calibrate the accelerometer upon a double tap if (input.Gestures.Count > 0) { GestureSample sample = input.Gestures[0]; if (sample.GestureType == GestureType.DoubleTap) { CalibrateGame(); input.Gestures.Clear(); } } } // Rotate the maze according to accelerometer data Vector3 currentAccelerometerState = Accelerometer.GetState().Acceleration; currentAccelerometerState.X -= AccelerometerCalibrationData.X; currentAccelerometerState.Y -= AccelerometerCalibrationData.Y; currentAccelerometerState.Z -= AccelerometerCalibrationData.Z; if (Microsoft.Devices.Environment.DeviceType == DeviceType.Device) { //Change the velocity according to acceleration reading maze.Rotation.Z = (float)Math.Round(MathHelper.ToRadians(currentAccelerometerState.Y * 30), 2); maze.Rotation.X = -(float)Math.Round(MathHelper.ToRadians(currentAccelerometerState.X * 30), 2); } else if (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator) { Vector3 Rotation = Vector3.Zero; if (currentAccelerometerState.X != 0) { if (currentAccelerometerState.X > 0) { Rotation += new Vector3(0, 0, -angularVelocity); } else { Rotation += new Vector3(0, 0, angularVelocity); } } if (currentAccelerometerState.Y != 0) { if (currentAccelerometerState.Y > 0) { Rotation += new Vector3(-angularVelocity, 0, 0); } else { Rotation += new Vector3(angularVelocity, 0, 0); } } // Limit the rotation of the maze to 30 degrees maze.Rotation.X = MathHelper.Clamp(maze.Rotation.X + Rotation.X, MathHelper.ToRadians(-30), MathHelper.ToRadians(30)); maze.Rotation.Z = MathHelper.Clamp(maze.Rotation.Z + Rotation.Z, MathHelper.ToRadians(-30), MathHelper.ToRadians(30)); } } } }