/// <summary> /// Constructor fills in the menu contents. /// </summary> public PauseMenuScreen(PauseBackgroundScreen pauseBG) : base("Pause", 0) { BGScreen = pauseBG; IsPopup = true; }
/// <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) { if (input == null) throw new ArgumentNullException("input"); // Look up inputs for the active player profile. int playerIndex = 0; KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex]; GamePadState gamePadState = input.CurrentGamePadStates[playerIndex]; PlayerIndex player; if (input.IsPauseGame(ControllingPlayer)) { PauseBackgroundScreen pauseBG = new PauseBackgroundScreen(); ScreenManager.AddScreen(pauseBG, ControllingPlayer); ScreenManager.AddScreen(new PauseMenuScreen(pauseBG), ControllingPlayer); } if(IsActive) { gameCars[7].ApplyThrottle(0f); gameCars[7].ApplyBrake(false); if(input.CurrentKeyboardStates[0].IsKeyDown(Keys.W) || input.CurrentKeyboardStates[0].IsKeyDown(Keys.Up)) { gameCars[7].ApplyThrottle(1f); } else gameCars[7].ApplyThrottle(0f); if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.S) || input.CurrentKeyboardStates[0].IsKeyDown(Keys.Down)) { gameCars[7].ApplyBrake(true); } else gameCars[7].ApplyBrake(false); if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.A) || input.CurrentKeyboardStates[0].IsKeyDown(Keys.Left)) { if (steeringAmount > 0f) steeringAmount -= 0.015f; steeringAmount -= 0.01f; steeringAmount = MathHelper.Clamp(steeringAmount, -0.5f, 0.5f); } else if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.D) || input.CurrentKeyboardStates[0].IsKeyDown(Keys.Right)) { if (steeringAmount < 0f) steeringAmount += 0.015f; steeringAmount += 0.01f; steeringAmount = MathHelper.Clamp(steeringAmount, -0.5f, 0.5f); } else if (input.CurrentGamePadStates[0].ThumbSticks.Left.X < -0.05f) { if (steeringAmount > 0f) steeringAmount -= 0.015f; steeringAmount -= 0.01f; steeringAmount = MathHelper.Clamp(steeringAmount, -0.5f * ((float)Math.Abs(input.CurrentGamePadStates[0].ThumbSticks.Left.X)), 0.5f); } else if (input.CurrentGamePadStates[0].ThumbSticks.Left.X > 0.05f) { if (steeringAmount < 0f) steeringAmount += 0.015f; steeringAmount += 0.01f; steeringAmount = MathHelper.Clamp(steeringAmount, -0.5f, 0.5f * ((float)Math.Abs(input.CurrentGamePadStates[0].ThumbSticks.Left.X))); } else steeringAmount = MathHelper.Lerp(steeringAmount, 0f, 0.15f); if (input.CurrentGamePadStates[0].Triggers.Right > 0.05f) { gameCars[7].ApplyThrottle(input.CurrentGamePadStates[0].Triggers.Right > 0.95f ? 1f : input.CurrentGamePadStates[0].Triggers.Right); } if (input.CurrentGamePadStates[0].Triggers.Left > 0.05f) { gameCars[7].ApplyBrake(true); } #if WINRT || WINDOWS_PHONE foreach(TouchLocation tl in TouchPanel.GetState()) { if (tl.State == TouchLocationState.Pressed || tl.State == TouchLocationState.Moved) { if(tl.Position.X> ScreenManager.Viewport.Width/2) gameCars[7].ApplyThrottle(1f); else gameCars[7].ApplyThrottle(0f); if(tl.Position.X< ScreenManager.Viewport.Width/2) gameCars[7].ApplyBrake(true); else gameCars[7].ApplyBrake(false); } } if(Math.Abs(input.AccelerometerVect.X)>0.05f) { steeringAmount = input.AccelerometerVect.X; steeringAmount = MathHelper.Clamp(steeringAmount, -0.5f, 0.5f); } //if (Math.Abs(input.AccelerometerVect.X) > 0.15f) //{ // if (input.AccelerometerVect.X > 0) gameCars[7].Steer(input.AccelerometerVect.X); // if (input.AccelerometerVect.X < 0) gameCars[7].Steer(input.AccelerometerVect.X); //} #endif gameCars[7].Steer(steeringAmount); } }