/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(InputState input, GameTime gameTime) { float timeDelta = (float)(gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f); if (input == null) { throw new ArgumentNullException("input"); } if (input.PauseGame) { // If they pressed pause, bring up the pause menu screen. ScreenManager.AddScreen(new PauseMenuScreen()); } m_kPlane.RotX = 0; m_kPlane.RotZ = 0; if (input.IsKeyHeld(Keys.Up)) { m_kPlane.RotX += -(float)Math.PI / 9; } if (input.IsKeyHeld(Keys.Down)) { m_kPlane.RotX += (float)Math.PI / 9; } if (input.IsKeyHeld(Keys.Left)) { m_kPlane.RotZ += (float)Math.PI / 9; } if (input.IsKeyHeld(Keys.Right)) { m_kPlane.RotZ += -(float)Math.PI / 9; } //for gamepad input (untested!!) //for forward/backward movement GamePadState gamePadState = input.CurrentGamePadStates[0]; m_kPlane.RotX += ((float)Math.PI / 9) * m_kLookingDir.Z * gamePadState.ThumbSticks.Left.Y; m_kPlane.RotZ += ((float)Math.PI / 9) * m_kLookingDir.X * gamePadState.ThumbSticks.Left.Y; //for Left/Right movement m_kPlane.RotX += ((float)Math.PI / 9) * m_kLookingDir.X * gamePadState.ThumbSticks.Left.X; m_kPlane.RotZ += ((float)Math.PI / 9) * m_kLookingDir.Z * gamePadState.ThumbSticks.Left.X; m_kPlane.setRotationOffset(player.position); }
/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(InputState input, GameTime gameTime) { float timeDelta = (float)(gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f); if (input == null) { throw new ArgumentNullException("input"); } if (input.PauseGame) { // If they pressed pause, bring up the pause menu screen. ScreenManager.AddScreen(new PauseMenuScreen()); } m_kPlane.RotX = 0; m_kPlane.RotZ = 0; if (input.IsKeyHeld(Keys.Up)) { m_kPlane.RotX += -(float)Math.PI / 9; } if (input.IsKeyHeld(Keys.Down)) { m_kPlane.RotX += (float)Math.PI / 9; } if (input.IsKeyHeld(Keys.Left)) { m_kPlane.RotZ += (float)Math.PI / 9; } if (input.IsKeyHeld(Keys.Right)) { m_kPlane.RotZ += -(float)Math.PI / 9; } m_kPlane.setRotationOffset(player.position); /* * //OLD SHIP FUNCTIONS * player.rotationVelocity = 0; * if (input.ShipTurnLeft) * { * player.rotationVelocity += 3; * } * if (input.ShipTurnRight) * { * player.rotationVelocity += -3; * } * Vector3 thrust = Vector3.Zero; * if (input.ShipMove) * { * thrust += 3500f * player.directionVec; * } * if (input.ReverseThrust) * { * thrust += -3500f * player.directionVec; * } * player.netForce = thrust; */ }
/// <summary> /// Lets the game respond to player input. Unlike the Update method, /// this will only be called when the gameplay screen is active. /// </summary> public override void HandleInput(InputState input, GameTime gameTime) { float timeDelta = (float)(gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000.0f); if (input == null) { throw new ArgumentNullException("input"); } if (input.PauseGame) { // If they pressed pause, bring up the pause menu screen. ScreenManager.AddScreen(new PauseMenuScreen()); } m_kPlane.RotX = 0; m_kPlane.RotZ = 0; Vector3 m_kLookingDir = player.position - gameCamera.GetCameraPosition(); m_kLookingDir.Y = 0f; m_kLookingDir.Normalize(); //m_kLookingDir = new Vector3(-1f, 0, 0); //The axis are flipped from what would be expected //If you want to go forward/backwards, you need to switch Z and X //If you want to go Left/Right you keep Z and X consistent if (input.IsKeyHeld(Keys.Up)) { m_kPlane.RotX += ((float)Math.PI / 9) * m_kLookingDir.Z; m_kPlane.RotZ += -((float)Math.PI / 9) * m_kLookingDir.X; } if (input.IsKeyHeld(Keys.Down)) { m_kPlane.RotX += -((float)Math.PI / 9) * m_kLookingDir.Z; m_kPlane.RotZ += ((float)Math.PI / 9) * m_kLookingDir.X; } if (input.IsKeyHeld(Keys.Left)) { m_kPlane.RotX += -((float)Math.PI / 9) * m_kLookingDir.X; m_kPlane.RotZ += -((float)Math.PI / 9) * m_kLookingDir.Z; } if (input.IsKeyHeld(Keys.Right)) { m_kPlane.RotX += ((float)Math.PI / 9) * m_kLookingDir.X; m_kPlane.RotZ += ((float)Math.PI / 9) * m_kLookingDir.Z; } /* * //for gamepad input (untested!!) * //for forward/backward movement * GamePadState gamePadState = input.CurrentGamePadStates[0]; * m_kPlane.RotX += ((float)Math.PI / 9) * m_kLookingDir.Z * gamePadState.ThumbSticks.Left.Y; * m_kPlane.RotZ += -((float)Math.PI / 9) * m_kLookingDir.X * gamePadState.ThumbSticks.Left.Y; * * //for Left/Right movement * m_kPlane.RotX += -((float)Math.PI / 9) * m_kLookingDir.X * gamePadState.ThumbSticks.Left.X; * m_kPlane.RotZ += -((float)Math.PI / 9) * m_kLookingDir.Z * gamePadState.ThumbSticks.Left.X; */ m_kPlane.setRotationOffset(player.position); //Manually changing the camera rotation based on user input if (input.IsADown) { manualCameraRotation += (float)Math.PI / 4 * (float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000; } if (input.IsDDown) { manualCameraRotation -= (float)Math.PI / 4 * (float)gameTime.ElapsedGameTime.Ticks / System.TimeSpan.TicksPerMillisecond / 1000; } gameCamera.ManualCameraRotation(manualCameraRotation, player); /* * //OLD SHIP FUNCTIONS * player.rotationVelocity = 0; * if (input.ShipTurnLeft) * { * player.rotationVelocity += 3; * } * if (input.ShipTurnRight) * { * player.rotationVelocity += -3; * } * Vector3 thrust = Vector3.Zero; * if (input.ShipMove) * { * thrust += 3500f * player.directionVec; * } * if (input.ReverseThrust) * { * thrust += -3500f * player.directionVec; * } * player.netForce = thrust; */ }