public override bool MatchAction(Reflex reflex, out object param) { GamePadSensor.PlayerId playerIdSensor = (GamePadSensor.PlayerId)reflex.targetSet.Param; if (this.playerId != playerIdSensor) { this.playerId = playerIdSensor; } GamePadInput pad = null; // Get the correct game pad. switch (playerId) { case GamePadSensor.PlayerId.All: pad = GamePadInput.GetGamePad0(); break; case GamePadSensor.PlayerId.One: pad = GamePadInput.GetGamePad1(); break; case GamePadSensor.PlayerId.Two: pad = GamePadInput.GetGamePad2(); break; case GamePadSensor.PlayerId.Three: pad = GamePadInput.GetGamePad3(); break; case GamePadSensor.PlayerId.Four: pad = GamePadInput.GetGamePad4(); break; } if (trigger == GamePadTrigger.LeftTrigger) { triggerValue = pad.LeftTrigger; } else if (trigger == GamePadTrigger.RightTrigger) { triggerValue = pad.RightTrigger; } // Return as a parameter a vector that can be used for input to the movement system, so // that players can drive and turn bots using gamepad triggers. param = new Vector2(0, triggerValue); return(triggerValue > 0); // only if pressed }
public override bool MatchAction(Reflex reflex, out object param) { bool result = false; // Only jump through hoops the first time to get the pad. if (ButtonState == null) { GamePadInput pad = null; // See if there's a filter defining which player we should be. If not, use pad0. if (playerId == GamePadSensor.PlayerId.Dynamic) { playerId = GamePadSensor.PlayerId.All; ReflexData data = reflex.Data; for (int i = 0; i < data.Filters.Count; i++) { if (data.Filters[i] is PlayerFilter) { playerId = ((PlayerFilter)data.Filters[i]).playerIndex; } } } // Get the correct game pad. switch (playerId) { case GamePadSensor.PlayerId.All: pad = GamePadInput.GetGamePad0(); break; case GamePadSensor.PlayerId.One: pad = GamePadInput.GetGamePad1(); break; case GamePadSensor.PlayerId.Two: pad = GamePadInput.GetGamePad2(); break; case GamePadSensor.PlayerId.Three: pad = GamePadInput.GetGamePad3(); break; case GamePadSensor.PlayerId.Four: pad = GamePadInput.GetGamePad4(); break; } // Get the correct game pad button. switch (button) { case GamePadButton.A: ButtonState = pad.ButtonA; break; case GamePadButton.B: ButtonState = pad.ButtonB; break; case GamePadButton.X: ButtonState = pad.ButtonX; break; case GamePadButton.Y: ButtonState = pad.ButtonY; break; case GamePadButton.LeftTrigger: ButtonState = pad.LeftTriggerButton; break; case GamePadButton.RightTrigger: ButtonState = pad.RightTriggerButton; break; } } result = ButtonState.IsPressed; // Return as a parameter a vector that can be used for input to the movement system, so // that players can drive and turn bots using gamepad buttons. param = new Vector2(0, 1); return(result); }