public override void HandleInput( InputState input ) { if ( IsActive ) base.HandleInput( input ); }
public override void HandleInput( InputState input ) { PlayerIndex playerIndex; if ( input.IsMenuSelect( ControllingPlayer, out playerIndex ) ) { // Raise the accepted event, then exit the message box. if ( Accepted != null ) Accepted( this, new PlayerIndexEventArgs( playerIndex ) ); GameCore.Instance.AudioManager.Play2DCue( "selectItem", 1f ); ExitScreen(); } else if ( input.IsMenuCancel( ControllingPlayer, out playerIndex ) ) { // Raise the cancelled event, then exit the message box. if ( Cancelled != null ) Cancelled( this, new PlayerIndexEventArgs( playerIndex ) ); GameCore.Instance.AudioManager.Play2DCue( "onCancel", 1f ); ExitScreen(); } }
public override void HandleInput( InputState input ) { if ( ScreenState != ScreenState.Active ) return; for ( int i = 0; i < 4; ++i ) { GamePadState lastPadState = input.LastGamePadStates[i]; GamePadState pad = input.CurrentGamePadStates[i]; if ( pad.IsConnected ) { if ( pad.IsButtonDown( Buttons.A ) && lastPadState.IsButtonUp( Buttons.A ) ) OnButtonAHit( (PlayerIndex)i, ref slots[i] ); else if ( pad.IsButtonDown( Buttons.B ) && lastPadState.IsButtonUp( Buttons.B ) ) OnButtonBHit( (PlayerIndex)i, ref slots[i] ); else if ( pad.IsButtonDown( Buttons.X ) && lastPadState.IsButtonUp( Buttons.X ) ) OnButtonXHit( (PlayerIndex)i, ref slots[i] ); else if ( pad.IsButtonDown( Buttons.Y ) && lastPadState.IsButtonUp( Buttons.Y ) ) OnButtonYHit( (PlayerIndex)i, ref slots[i] ); } } }
/// <summary> /// Allows the screen to handle user input. Unlike Update, this method /// is only called when the screen is active, and not when some other /// screen has taken the focus. /// </summary> public virtual void HandleInput( InputState input ) { }
public override void HandleInput( InputState input ) { PlayerIndex pi; //Exit if ( input.IsNewButtonPress( Microsoft.Xna.Framework.Input.Buttons.B, null, out pi ) ) { ExitScreen(); } if ( input.IsNewButtonPress( Buttons.Y, null, out pi ) ) { ScreenManager.AddScreen( faqScreen, null ); } //Control which filter type is being used if ( input.IsNewButtonPress( Buttons.X, null, out pi ) ) { leaderBoardTypeIndex++; if ( leaderBoardTypeIndex >= leaderBoardTypes.Count ) leaderBoardTypeIndex = 0; } //Control the scores that are shown on the screen if ( input.IsMenuDown( null ) ) scoreDisplayStartIndex++; if ( input.IsMenuUp( null ) ) scoreDisplayStartIndex--; if ( input.IsNewButtonPress( Buttons.LeftTrigger, null, out pi ) ) scoreDisplayStartIndex -= scoresDisplayedPerPage; if ( input.IsNewButtonPress( Buttons.RightTrigger, null, out pi ) ) scoreDisplayStartIndex += scoresDisplayedPerPage; scoreDisplayStartIndex = (int)MathHelper.Clamp( scoreDisplayStartIndex, 0, scoreCount - scoresDisplayedPerPage ); base.HandleInput( input ); }
/// <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" ); if ( firstFrame ) { firstFrame = false; return; } // The game pauses either if the user presses the pause button, or if // they unplug the active gamepad. This requires us to keep track of // whether a gamepad was ever plugged in, because we don't want to pause // on PC if they are playing with a keyboard and have no gamepad at all! bool gamePadDisconnected = false; for ( int i = 0; i < 4; ++i ) { if ( input.LastGamePadStates[i].IsConnected && !input.CurrentGamePadStates[i].IsConnected ) { gamePadDisconnected = true; break; } } if ( ( input.IsPauseGame( null ) || gamePadDisconnected ) && ( ScreenState == ScreenState.Active ) && !GameOver ) { GameCore.Instance.AudioManager.Play2DCue( "pause", 1f ); ScreenManager.AddScreen( pauseScreen, null ); } else { ReadOnlyCollection<Player> players = ObjectTable.GetObjects<Player>(); int nPlayers = players.Count; for ( int i = 0; i < nPlayers; ++i ) players[i].HandleInput( input ); } }
/// <summary> /// Responds to user input, changing the selected entry and accepting /// or cancelling the menu. /// </summary> public override void HandleInput( InputState input ) { ReadOnlyCollection<MenuEntry> menuEntries = MenuEntries; ReadOnlyCollection<ImageMenuEntry> imageMenuEntries = ImageMenuEntries; PlayerIndex playerIndex; // If there is a wheel menu, handle left and right input if ( menuItems.AllObjectsList.Exists( item => item is WheelMenu ) ) { WheelMenu wheel = menuItems.GetObjects<WheelMenu>()[0]; if ( wheel.AcceptingInput ) { if ( input.IsMenuLeft( ControllingPlayer ) ) wheel.RotateCW(); if ( input.IsMenuRight( ControllingPlayer ) ) wheel.RotateCCW(); } } else if ( imageMenuEntries != null && imageMenuEntries.Count != 0 ) { // Move to the previous menu entry? if ( input.IsMenuUp( ControllingPlayer ) ) { imageMenuEntries[selectedEntry--].Focused = false; if ( selectedEntry < 0 ) selectedEntry = imageMenuEntries.Count - 1; imageMenuEntries[selectedEntry].Focused = true; GameCore.Instance.AudioManager.Play2DCue( "whoosh", 1f ); } // Move to the next menu entry? if ( input.IsMenuDown( ControllingPlayer ) ) { imageMenuEntries[selectedEntry++].Focused = false; if ( selectedEntry >= imageMenuEntries.Count ) selectedEntry = 0; imageMenuEntries[selectedEntry].Focused = true; GameCore.Instance.AudioManager.Play2DCue( "whoosh", 1f ); } } else if ( menuEntries != null && menuEntries.Count != 0 ) { // Move to the previous menu entry? if ( input.IsMenuUp( ControllingPlayer ) ) { menuEntries[selectedEntry--].Focused = false; if ( selectedEntry < 0 ) selectedEntry = menuEntries.Count - 1; menuEntries[selectedEntry].Focused = true; GameCore.Instance.AudioManager.Play2DCue( "whoosh", 1f ); } // Move to the next menu entry? if ( input.IsMenuDown( ControllingPlayer ) ) { menuEntries[selectedEntry++].Focused = false; if ( selectedEntry >= menuEntries.Count ) selectedEntry = 0; menuEntries[selectedEntry].Focused = true; GameCore.Instance.AudioManager.Play2DCue( "whoosh", 1f ); } } if ( input.IsMenuSelect( ControllingPlayer, out playerIndex ) ) OnSelectEntry( playerIndex ); else if ( input.IsMenuRight( ControllingPlayer, out playerIndex ) ) OnIncrementEntry( playerIndex ); else if ( input.IsMenuLeft( ControllingPlayer, out playerIndex ) ) OnDecrementEntry( playerIndex ); else if ( input.IsMenuCancel( ControllingPlayer, out playerIndex ) ) OnCancel( playerIndex ); }
public override void Update( GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { base.Update( gameTime, otherScreenHasFocus, coveredByOtherScreen ); if ( otherScreensAreGone ) { if ( backgroundThread != null ) { loadStartTime = gameTime; backgroundThread.Start(); } ScreenManager.RemoveScreen( this ); foreach ( GameScreen screen in screensToLoad ) { if ( screen != null ) { ScreenManager.AddScreen( screen, ControllingPlayer ); } } if ( backgroundThread != null ) { doneLoading = true; InputState input = new InputState(); PlayerIndex actingPlayer; do { input.Update(); } while ( !input.IsNewButtonPress( Buttons.Start, null, out actingPlayer ) && !input.IsNewButtonPress( Buttons.A, null, out actingPlayer ) ); backgroundThreadExit.Set(); backgroundThread.Join(); if ( GameplayScreen.Instance.BackgroundMusic == null ) { ScreenManager.MenuTrack.Pause(); GameplayScreen.Instance.BackgroundMusic = GameCore.Instance.AudioManager.Play2DCue( "banjoBreakdown", GameCore.Instance.MusicVolume ); GameplayScreen.Instance.BackgroundMusic.Pause(); GameCore.Instance.MusicVolumeChanged += GameplayScreen.Instance.ChangeMusicVolume; } } ScreenManager.Game.ResetElapsedTime(); } }
private void GetPlayerInput( PlayerIndex playerIndex, InputState input, out PlayerInput playerInput ) { if ( playerIndex < PlayerIndex.One ) { playerAI.GetInput( out playerInput ); } else { playerInput.ButtonAHit = input.IsNewButtonPress( Buttons.A, playerIndex, out playerIndex ); playerInput.ButtonBHit = input.IsNewButtonPress( Buttons.B, playerIndex, out playerIndex ); playerInput.ButtonXHit = input.IsNewButtonPress( Buttons.X, playerIndex, out playerIndex ); playerInput.ButtonYHit = input.IsNewButtonPress( Buttons.Y, playerIndex, out playerIndex ); playerInput.ButtonADown = input.CurrentGamePadStates[(int)playerIndex].IsButtonDown( Buttons.A ); playerInput.ButtonBDown = input.CurrentGamePadStates[(int)playerIndex].IsButtonDown( Buttons.B ); if ( !playerInput.ButtonBDown ) playerInput.ButtonBDown = input.CurrentGamePadStates[(int)playerIndex].IsButtonDown( Buttons.X ); GamePadState gamePadState = input.CurrentGamePadStates[(int)playerIndex]; playerInput.LeftTrigger = gamePadState.Triggers.Left; playerInput.RightTrigger = gamePadState.Triggers.Right; playerInput.LeftBumper = gamePadState.IsButtonDown( Buttons.LeftShoulder ); playerInput.RightBumper = gamePadState.IsButtonDown( Buttons.RightShoulder ); playerInput.LeftStick = gamePadState.ThumbSticks.Left; playerInput.LeftDpad = gamePadState.DPad.Left == ButtonState.Pressed; playerInput.RightDpad = gamePadState.DPad.Right == ButtonState.Pressed; playerInput.DownDpad = gamePadState.DPad.Down == ButtonState.Pressed; } }
public void HandleInput( InputState input ) { PlayerInput playerInput; GetPlayerInput( PlayerIndex, input, out playerInput ); PhysCircle circle = BoundingCircle; // powerups PlayerIndex playerIndex = PlayerIndex; if ( ( playerInput.ButtonYHit ) && Powerup != null && Powerup.Type != PowerupType.GoldenShake ) { if ( !Screen.GameOver ) Powerup.Use(); } // movement float forceY = 0f; float forceX = 0f; float maxVelX = 4f; bool leftHeld = ( playerInput.LeftStick.X < 0 || playerInput.LeftDpad ) && !( playerInput.LeftStick.X > 0 || playerInput.RightDpad ); bool rightHeld = ( playerInput.LeftStick.X > 0 || playerInput.RightDpad ) && !( playerInput.LeftStick.X < 0 || playerInput.LeftDpad ); Boosting = false; if ( !Screen.GameOver ) { if ( playerInput.LeftTrigger != 0f || playerInput.LeftBumper || ( playerInput.ButtonBDown && leftHeld ) || ( playerInput.ButtonBDown && !rightHeld && circle.Velocity.X < 0 ) ) { Boosting = true; forceX = -20f * BoundingCircle.Mass; maxVelX = 6f; } else if ( playerInput.RightTrigger != 0f || playerInput.RightBumper || ( playerInput.ButtonBDown && rightHeld ) || ( playerInput.ButtonBDown && !leftHeld && circle.Velocity.X > 0 ) ) { Boosting = true; forceX = 20f * BoundingCircle.Mass; maxVelX = 6f; } } float maxAngVel = MathHelper.TwoPi; float torqueScale = -100f; float torque = torqueScale * playerInput.LeftStick.X; if ( playerInput.LeftDpad ) torque = -torqueScale; else if ( playerInput.RightDpad ) torque = torqueScale; float elapsed = (float)lastGameTime.ElapsedGameTime.TotalSeconds; // torque if ( circle.AngularVelocity < 0f && torque < 0f ) { float reqTorque = PhysBody.GetForceRequired( -maxAngVel, circle.AngularVelocity, circle.Torque, circle.MomentOfInertia, elapsed ); torque = Math.Max( torque, reqTorque ); } else if ( circle.AngularVelocity > 0f && torque > 0f ) { float reqTorque = PhysBody.GetForceRequired( maxAngVel, circle.AngularVelocity, circle.Torque, circle.MomentOfInertia, elapsed ); torque = Math.Min( torque, reqTorque ); } circle.Torque += torque; // linear force if ( Boosting ) { if ( circle.Velocity.X < 0f && forceX < 0f ) { forceX = Math.Max( forceX, PhysBody.GetForceRequired( -maxVelX, circle.Velocity.X, circle.Force.X, circle.Mass, elapsed ) ); } else if ( circle.Velocity.X > 0f && forceX > 0f ) { forceX = Math.Min( forceX, PhysBody.GetForceRequired( maxVelX, circle.Velocity.X, circle.Force.X, circle.Mass, elapsed ) ); } float maxBurn = BoostBurnRate * elapsed; float burn = Math.Min( HUD.Boost, maxBurn ); HUD.Boost -= burn; circle.Force += ( burn / maxBurn ) * new Vector2( forceX, forceY ); } else { HUD.Boost = MathHelper.Clamp( HUD.Boost + BoostRechargeRate * elapsed, 0f, 1f ); if ( playerInput.LeftStick.Y < -.75f || playerInput.DownDpad ) { //circle.Force += 1.0f * Screen.PhysicsSpace.Gravity; } } /*/// jumping float totalTime = Screen.AccumulatedTime; if ( playerInput.ButtonAHit ) { if ( lastJump != lastCollision && totalTime - lastCollision < jumpTimeout ) { Jump( circle ); lastJump = lastCollision; } else { jumpRegistered = totalTime; } } if ( jumpRegistered != 0f ) { if ( circle.Touching != null ) { Jump( circle ); lastJump = lastCollision; jumpRegistered = 0f; } else if ( totalTime - jumpRegistered > jumpTimeout ) { jumpRegistered = 0f; } } /*/ // updward boosting if ( playerInput.ButtonADown && HUD.Boost != 0 && !Screen.GameOver ) { float maxBurn = BoostBurnRate * elapsed; float burn = Math.Min( HUD.Boost, maxBurn ); HUD.Boost -= burn; Boosting = true; float boostScale = burn / maxBurn; circle.Force += 2f * circle.Mass * -Screen.PhysicsSpace.Gravity * boostScale; } /**/ }