public bool GetDPad(DPad dir) //Returns if the specified DPad direction is being pushed. { string Data = controller.GetState().Gamepad.Buttons.ToString(); Console.WriteLine(dir.ToString()); return(Data == dir.ToString()); }
void Start() { mc = GetComponent <MoveController>(); dc = GetComponent <DPad>(); gc = GetComponent <GameController>(); uc = GetComponent <UIController>(); }
public void Commit(ulong updateTick, float deltaTime) { int controlCount = Controls.Length; for (int i = 0; i < controlCount; i++) { var control = Controls[i]; if (control != null) { control.Commit(); if (control.HasChanged) { LastChangeTick = updateTick; } } } if (IsKnown) { GetControl(InputControlType.Command).CommitWithState(AnyCommandControlIsPressed(), updateTick, deltaTime); } LeftStickX.CommitWithSides(LeftStickLeft, LeftStickRight, updateTick, deltaTime); LeftStickY.CommitWithSides(LeftStickDown, LeftStickUp, updateTick, deltaTime, InputManager.InvertYAxis); LeftStick.UpdateWithAxes(LeftStickX, LeftStickY, updateTick, deltaTime); RightStickX.CommitWithSides(RightStickLeft, RightStickRight, updateTick, deltaTime); RightStickY.CommitWithSides(RightStickDown, RightStickUp, updateTick, deltaTime, InputManager.InvertYAxis); RightStick.UpdateWithAxes(RightStickX, RightStickY, updateTick, deltaTime); DPadX.CommitWithSides(DPadLeft, DPadRight, updateTick, deltaTime); DPadY.CommitWithSides(DPadDown, DPadUp, updateTick, deltaTime, InputManager.InvertYAxis); DPad.UpdateWithAxes(DPadX, DPadY, updateTick, deltaTime); }
public void PostUpdate(ulong updateTick, float deltaTime) { // Apply post-processing to controls. foreach (InputControl control in Controls.IgnoreNulls()) { if (control.RawValue != null) { control.UpdateWithValue(control.RawValue.Value, updateTick); } else if (control.PreValue != null) { control.UpdateWithValue(ProcessAnalogControlValue(control, deltaTime), updateTick); } control.PostUpdate(updateTick); if (control.HasChanged) { LastChangeTick = updateTick; } } // Update two-axis controls. LeftStick.Update(LeftStickX, LeftStickY, updateTick); RightStick.Update(RightStickX, RightStickY, updateTick); Vector2 dpv = DPadVector; DPad.Update(dpv.x, dpv.y, updateTick); }
private void ProcessDPad(ulong updateTick, float deltaTime) { float x = Utility.ValueFromSides(DPadLeft.NextRawValue, DPadRight.NextRawValue); float y = Utility.ValueFromSides(DPadDown.NextRawValue, DPadUp.NextRawValue, InputManager.InvertYAxis); Vector2 vector; if (RawSticks || DPadLeft.Raw || DPadRight.Raw || DPadUp.Raw || DPadDown.Raw) { vector = new Vector2(x, y); } else { float lowerDeadZone = Utility.Max(DPadLeft.LowerDeadZone, DPadRight.LowerDeadZone, DPadUp.LowerDeadZone, DPadDown.LowerDeadZone); float upperDeadZone = Utility.Min(DPadLeft.UpperDeadZone, DPadRight.UpperDeadZone, DPadUp.UpperDeadZone, DPadDown.UpperDeadZone); vector = Utility.ApplySeparateDeadZone(x, y, lowerDeadZone, upperDeadZone); } DPad.Raw = true; DPad.UpdateWithAxes(vector.x, vector.y, updateTick, deltaTime); DPadX.Raw = true; DPadX.CommitWithValue(vector.x, updateTick, deltaTime); DPadY.Raw = true; DPadY.CommitWithValue(vector.y, updateTick, deltaTime); DPadLeft.SetValue(DPad.Left.Value, updateTick); DPadRight.SetValue(DPad.Right.Value, updateTick); DPadUp.SetValue(DPad.Up.Value, updateTick); DPadDown.SetValue(DPad.Down.Value, updateTick); }
public void ClearInputState() { LeftStickX.ClearInputState(); LeftStickY.ClearInputState(); LeftStick.ClearInputState(); RightStickX.ClearInputState(); RightStickY.ClearInputState(); RightStick.ClearInputState(); DPadX.ClearInputState(); DPadY.ClearInputState(); DPad.ClearInputState(); var controlCount = Controls.Length; for (int i = 0; i < controlCount; i++) { var control = Controls[i]; if (control != null) { control.ClearInputState(); } } }
void ProcessDPad(ulong updateTick, float deltaTime) { var x = Utility.ValueFromSides(DPadLeft.NextRawValue, DPadRight.NextRawValue); var y = Utility.ValueFromSides(DPadDown.NextRawValue, DPadUp.NextRawValue, InputManager.InvertYAxis); Vector2 v; if (RawSticks || DPadLeft.Raw || DPadRight.Raw || DPadUp.Raw || DPadDown.Raw) { v = new Vector2(x, y); } else { var lowerDeadZone = Utility.Max(DPadLeft.LowerDeadZone, DPadRight.LowerDeadZone, DPadUp.LowerDeadZone, DPadDown.LowerDeadZone); var upperDeadZone = Utility.Min(DPadLeft.UpperDeadZone, DPadRight.UpperDeadZone, DPadUp.UpperDeadZone, DPadDown.UpperDeadZone); v = DPad.DeadZoneFunc(x, y, lowerDeadZone, upperDeadZone); } DPad.Raw = true; DPad.UpdateWithAxes(v.x, v.y, updateTick, deltaTime); DPadX.Raw = true; DPadX.CommitWithValue(v.x, updateTick, deltaTime); DPadY.Raw = true; DPadY.CommitWithValue(v.y, updateTick, deltaTime); DPadLeft.SetValue(DPad.Left.Value, updateTick); DPadRight.SetValue(DPad.Right.Value, updateTick); DPadUp.SetValue(DPad.Up.Value, updateTick); DPadDown.SetValue(DPad.Down.Value, updateTick); }
public ControllerXbox360(params int[] joystickId) { AddButton(Controls.A); AddButton(Controls.B); AddButton(Controls.X); AddButton(Controls.Y); AddButton(Controls.RB); AddButton(Controls.LB); AddButton(Controls.LStickClick); AddButton(Controls.RStickClick); AddButton(Controls.Start); AddButton(Controls.Back); AddButton(Controls.RT); AddButton(Controls.LT); AddButton(Controls.Up); AddButton(Controls.Down); AddButton(Controls.Left); AddButton(Controls.Right); AddAxis(Controls.LStick); AddAxis(Controls.RStick); AddAxis(Controls.DPad); AddAxis(Controls.Triggers); foreach (var joy in joystickId) { A.AddJoyButton(0, joy); B.AddJoyButton(1, joy); X.AddJoyButton(2, joy); Y.AddJoyButton(3, joy); LB.AddJoyButton(4, joy); RB.AddJoyButton(5, joy); Back.AddJoyButton(6, joy); Start.AddJoyButton(7, joy); LeftStickClick.AddJoyButton(8, joy); RightStickClick.AddJoyButton(9, joy); RT.AddAxisButton(AxisButton.ZMinus, joy); LT.AddAxisButton(AxisButton.ZPlus, joy); LeftStick.AddJoyAxis(JoyAxis.X, JoyAxis.Y, joy); RightStick.AddJoyAxis(JoyAxis.U, JoyAxis.R, joy); DPad.AddJoyAxis(JoyAxis.PovX, JoyAxis.PovY, joy); Triggers.AddJoyAxis(JoyAxis.Z, JoyAxis.Z, joy); Up .AddAxisButton(AxisButton.YMinus, joy) .AddAxisButton(AxisButton.PovYMinus, joy); Down .AddAxisButton(AxisButton.YPlus, joy) .AddAxisButton(AxisButton.PovYPlus, joy); Right .AddAxisButton(AxisButton.XPlus, joy) .AddAxisButton(AxisButton.PovXPlus, joy); Left .AddAxisButton(AxisButton.XMinus, joy) .AddAxisButton(AxisButton.PovXMinus, joy); } }
/// <summary> /// Serves as a hash function for a <see cref="T:Microsoft.Xna.Framework.Input.GamePadState"/> object. /// </summary> /// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a /// hash table.</returns> public override int GetHashCode() { unchecked { var hash = PacketNumber; hash = (hash * 397) ^ Buttons.GetHashCode(); hash = (hash * 397) ^ DPad.GetHashCode(); hash = (hash * 397) ^ ThumbSticks.GetHashCode(); hash = (hash * 397) ^ Triggers.GetHashCode(); return(hash); } }
public void ClearInputState() { LeftStick.ClearInputState(); RightStick.ClearInputState(); DPad.ClearInputState(); int count = Controls.Count; for (int i = 0; i < count; i++) { Controls[i]?.ClearInputState(); } }
private void Start() { mc = GetComponent <MoveController>(); uc = GetComponent <UIController>(); ic = GetComponent <InputController>(); dpad = GetComponent <DPad>(); //DEBUG for (int i = 0; i < allSlots.Length; i++) { allSlots[i].GetComponentInChildren <SpriteRenderer>().enabled = false; } }
public void ClearInputState() { LeftStick.ClearInputState(); RightStick.ClearInputState(); DPad.ClearInputState(); var controlsCount = Controls.Count; for (var i = 0; i < controlsCount; i++) { var control = Controls[i]; if (control != null) { control.ClearInputState(); } } }
public static bool DPadUp(DPad dPad, int playerNr) { switch (dPad) { case DPad.Up: if (currentStates[playerNr].DPad.Up == ButtonState.Released && prevStates[playerNr].DPad.Up == ButtonState.Pressed) { return(true); } break; case DPad.Down: if (currentStates[playerNr].DPad.Down == ButtonState.Released && prevStates[playerNr].DPad.Down == ButtonState.Pressed) { return(true); } break; case DPad.Left: if (currentStates[playerNr].DPad.Left == ButtonState.Released && prevStates[playerNr].DPad.Left == ButtonState.Pressed) { return(true); } break; case DPad.Right: if (currentStates[playerNr].DPad.Right == ButtonState.Released && prevStates[playerNr].DPad.Right == ButtonState.Pressed) { return(true); } break; default: break; } return(false); }
public void SendDpad(DPad button, int Delay) { try { if (Program.botRunning || _serialPort.IsOpen) { newFrame = new InputFrame(); newFrame.DPad = button; //newFrame.Wait = 1; Update(newFrame); BotWait(150); newFrame.DPad = DPad.None; Update(newFrame); BotWait(Delay); } } catch (Exception ex) { Program.form.ApplyLog(ex.Message); } }
internal void ProcessDPad() { var lowerDeadZone = Utility.Max(DPadLeft.LowerDeadZone, DPadRight.LowerDeadZone, DPadUp.LowerDeadZone, DPadDown.LowerDeadZone); var upperDeadZone = Utility.Min(DPadLeft.UpperDeadZone, DPadRight.UpperDeadZone, DPadUp.UpperDeadZone, DPadDown.UpperDeadZone); var x = Utility.ValueFromSides(DPadLeft.NextRawValue, DPadRight.NextRawValue); var y = Utility.ValueFromSides(DPadDown.NextRawValue, DPadUp.NextRawValue, InputManager.InvertYAxis); var v = Utility.ApplyCircularDeadZone(x, y, lowerDeadZone, upperDeadZone); DPad.Raw = true; DPad.UpdateWithAxes(v.X, v.Y); DPadX.Raw = true; DPadX.CommitWithValue(v.X); DPadY.Raw = true; DPadY.CommitWithValue(v.Y); DPadLeft.SetValue(DPad.Left.Value); DPadRight.SetValue(DPad.Right.Value); DPadUp.SetValue(DPad.Up.Value); DPadDown.SetValue(DPad.Down.Value); }
/// <summary> /// Determine if a button was pressed. /// </summary> /// <param name="button">The <see cref="DPad"/> button to check.</param> /// <returns></returns> public static bool IsPressed(DPad button) { int i = (int)button; return !_ports1[i].Read(); }
//void _Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) void _Timer_Elapsed(object whatever) { //_Timer.Stop(); DPad[] oDirection = new DPad[4]; Button oBtn = new Button(); HatPosition[] oHatDirection = new HatPosition[4]; try { for (int i = 0; i < 4; i++) { var cap = OpenTK.Input.Joystick.GetCapabilities(i); var state = OpenTK.Input.Joystick.GetState(i); if (!state.IsConnected || (cap.ButtonCount == 16)) continue; System.Diagnostics.Debug.Print(state.ToString()); oBtn.A = state.IsButtonDown(JoystickButton.Button1); oBtn.B = state.IsButtonDown(JoystickButton.Button2); oBtn.X = state.IsButtonDown(JoystickButton.Button3); oBtn.Y = state.IsButtonDown(JoystickButton.Button0); oBtn.L = state.IsButtonDown(JoystickButton.Button6); oBtn.R = state.IsButtonDown(JoystickButton.Button7); oBtn.LB = false; oBtn.RB = false; oBtn.Select = state.IsButtonDown(JoystickButton.Button8); oBtn.Start = state.IsButtonDown(JoystickButton.Button9); JoystickHatState jhs = state.GetHat(JoystickHat.Hat0); oHatDirection[i] = jhs.Position; int nXAxis = (int)Math.Round(state.GetAxis(JoystickAxis.Axis0), 0); int nYAxis = (int)Math.Round(state.GetAxis(JoystickAxis.Axis1), 0); // 左邊磨菇頭... if ((nXAxis == 0 && nYAxis == 0)) { oDirection[i] = DPad.None; } if (nYAxis > 0) oDirection[i] = DPad.Up; if (nYAxis < 0) oDirection[i] = DPad.Down; if (oBtn.A || oBtn.B || oBtn.X || oBtn.Y || oBtn.L || oBtn.R || oBtn.LB || oBtn.RB || oBtn.Select || oBtn.Start || oDirection[i] != DPad.None || jhs.Position != HatPosition.Centered) { JoystickPressedEventHandler handler = JoystickPressed; if (handler != null) { JoystickPressedEventArgs evt = new JoystickPressedEventArgs(); evt.DPadDirection = oDirection[i]; evt.Buttons = oBtn; evt.HatDirection = oHatDirection[i]; evt.TraceMessage = "Joystick[" + i + "]: " + state.ToString(); handler(evt); } } else { JoystickTraceEventHandler hander2 = JoystickTrace; if (hander2 != null) { JoystickTraceEventArgs evt2 = new JoystickTraceEventArgs(); evt2.TraceMessage = "Joystick[" + i + "]: " + state.ToString(); hander2(evt2); } } } } catch (Exception ex){ } //_Timer.Start(); }
public virtual void Update(float elapsed) { sinceCheckedConnected += elapsed; if (sinceCheckedConnected >= ConnectedCheckFrequency) { sinceCheckedConnected -= ConnectedCheckFrequency; Connected = GamePad.GetState(PlayerIndex).IsConnected; } if (!Connected) { return; } GamePadState gamepadState; try { gamepadState = GamePad.GetState(PlayerIndex, GamePadDeadZone.None); } catch { return; } // Vibration if (leftMotor.Active) { leftMotor = UpdateMotor(leftMotor, elapsed); } if (rightMotor.Active) { rightMotor = UpdateMotor(rightMotor, elapsed); } if (leftMotor.LastAmount != leftMotor.CurrentAmount || rightMotor.LastAmount != rightMotor.CurrentAmount) { GamePad.SetVibration(PlayerIndex, leftMotor.CurrentAmount, rightMotor.CurrentAmount); } // Shoulders LeftShoulder = LeftShoulder.NextState(gamepadState.Buttons.LeftShoulder == ButtonState.Pressed, elapsed); RightShoulder = RightShoulder.NextState(gamepadState.Buttons.RightShoulder == ButtonState.Pressed, elapsed); // Triggers LeftTrigger = LeftTrigger.NextState(gamepadState.Triggers.Left, elapsed); RightTrigger = RightTrigger.NextState(gamepadState.Triggers.Right, elapsed); // Buttons Start = Start.NextState(gamepadState.Buttons.Start == ButtonState.Pressed); Back = Back.NextState(gamepadState.Buttons.Back == ButtonState.Pressed); A = A.NextState(gamepadState.Buttons.A == ButtonState.Pressed, elapsed); B = B.NextState(gamepadState.Buttons.B == ButtonState.Pressed, elapsed); X = X.NextState(gamepadState.Buttons.X == ButtonState.Pressed, elapsed); Y = Y.NextState(gamepadState.Buttons.Y == ButtonState.Pressed, elapsed); // D-Pad DPad = DPad.NextState(gamepadState.DPad.Up == ButtonState.Pressed, gamepadState.DPad.Down == ButtonState.Pressed, gamepadState.DPad.Left == ButtonState.Pressed, gamepadState.DPad.Right == ButtonState.Pressed, elapsed); // Deadzone that shit const float DeadZone = 0.2f; var left = new Vector2(gamepadState.ThumbSticks.Left.X, gamepadState.ThumbSticks.Left.Y); var right = new Vector2(gamepadState.ThumbSticks.Right.X, gamepadState.ThumbSticks.Right.Y); if (Math.Abs(left.x) < DeadZone) { left.x = 0; } else { left.x = (left.x - DeadZone * Math.Sign(left.x)) / (1 - DeadZone); } if (Math.Abs(left.y) < DeadZone) { left.y = 0; } else { left.y = (left.y - DeadZone * Math.Sign(left.y)) / (1 - DeadZone); } if (Math.Abs(right.x) < DeadZone) { right.x = 0; } else { right.x = (right.x - DeadZone * Math.Sign(right.x)) / (1 - DeadZone); } if (Math.Abs(right.y) < DeadZone) { right.y = 0; } else { right.y = (right.y - DeadZone * Math.Sign(right.y)) / (1 - DeadZone); } // Thumbsticks LeftStick = LeftStick.NextState(left, gamepadState.Buttons.LeftStick == ButtonState.Pressed, elapsed); RightStick = LeftStick.NextState(right, gamepadState.Buttons.RightStick == ButtonState.Pressed, elapsed); }
public virtual void Update(float elapsed) { sinceCheckedConnected += elapsed; if (sinceCheckedConnected >= ConnectedCheckFrequency) { sinceCheckedConnected -= ConnectedCheckFrequency; if (Application.platform.IsOSX()) { Connected = Input.GetJoystickNames().Length > (int)playerIndex; } else if (Application.platform.IsWindows()) { Connected = GamePad.GetState(PlayerIndex).IsConnected; } } if (!Connected) { return; } // XInput.NET if (Application.platform.IsWindows()) { GamePadState gamepadState; try { gamepadState = GamePad.GetState(PlayerIndex, GamePadDeadZone.None); } catch { return; } // Vibration if (leftMotor.Active) { leftMotor = UpdateMotor(leftMotor, elapsed); } if (rightMotor.Active) { rightMotor = UpdateMotor(rightMotor, elapsed); } if (leftMotor.LastAmount != leftMotor.CurrentAmount || rightMotor.LastAmount != rightMotor.CurrentAmount) { GamePad.SetVibration(PlayerIndex, leftMotor.CurrentAmount, rightMotor.CurrentAmount); } // Shoulders LeftShoulder = LeftShoulder.NextState(gamepadState.Buttons.LeftShoulder == ButtonState.Pressed, elapsed); RightShoulder = RightShoulder.NextState(gamepadState.Buttons.RightShoulder == ButtonState.Pressed, elapsed); // Triggers LeftTrigger = LeftTrigger.NextState(gamepadState.Triggers.Left, elapsed); RightTrigger = RightTrigger.NextState(gamepadState.Triggers.Right, elapsed); // Buttons Start = Start.NextState(gamepadState.Buttons.Start == ButtonState.Pressed, elapsed); Back = Back.NextState(gamepadState.Buttons.Back == ButtonState.Pressed, elapsed); A = A.NextState(gamepadState.Buttons.A == ButtonState.Pressed, elapsed); B = B.NextState(gamepadState.Buttons.B == ButtonState.Pressed, elapsed); X = X.NextState(gamepadState.Buttons.X == ButtonState.Pressed, elapsed); Y = Y.NextState(gamepadState.Buttons.Y == ButtonState.Pressed, elapsed); // D-Pad DPad = DPad.NextState(gamepadState.DPad.Up == ButtonState.Pressed, gamepadState.DPad.Down == ButtonState.Pressed, gamepadState.DPad.Left == ButtonState.Pressed, gamepadState.DPad.Right == ButtonState.Pressed, elapsed); // Deadzone that shit const float DeadZone = 0.1f; var left = new Vector2(gamepadState.ThumbSticks.Left.X, gamepadState.ThumbSticks.Left.Y); var right = new Vector2(gamepadState.ThumbSticks.Right.X, gamepadState.ThumbSticks.Right.Y); if (Math.Abs(left.x) < DeadZone) { left.x = 0; } else { left.x = (left.x - DeadZone * Math.Sign(left.x)) / (1 - DeadZone); } if (Math.Abs(left.y) < DeadZone) { left.y = 0; } else { left.y = (left.y - DeadZone * Math.Sign(left.y)) / (1 - DeadZone); } if (Math.Abs(right.x) < DeadZone) { right.x = 0; } else { right.x = (right.x - DeadZone * Math.Sign(right.x)) / (1 - DeadZone); } if (Math.Abs(right.y) < DeadZone) { right.y = 0; } else { right.y = (right.y - DeadZone * Math.Sign(right.y)) / (1 - DeadZone); } // Thumbsticks LeftStick = LeftStick.NextState(left, gamepadState.Buttons.LeftStick == ButtonState.Pressed, elapsed); RightStick = LeftStick.NextState(right, gamepadState.Buttons.RightStick == ButtonState.Pressed, elapsed); } // Tattiebogle if (Application.platform.IsOSX()) { string playerPrefix = "Player" + ((int)PlayerIndex + 1); // Shoulders LeftShoulder = LeftShoulder.NextState(Input.GetButton(playerPrefix + " LeftShoulder"), elapsed); RightShoulder = RightShoulder.NextState(Input.GetButton(playerPrefix + " RightShoulder"), elapsed); // Triggers LeftTrigger = LeftTrigger.NextState(Input.GetAxisRaw(playerPrefix + " LeftTrigger"), elapsed); RightTrigger = RightTrigger.NextState(Input.GetAxisRaw(playerPrefix + " RightTrigger"), elapsed); // Buttons Start = Start.NextState(Input.GetButton(playerPrefix + " Start"), elapsed); Back = Back.NextState(Input.GetButton(playerPrefix + " Back"), elapsed); A = A.NextState(Input.GetButton(playerPrefix + " A"), elapsed); B = B.NextState(Input.GetButton(playerPrefix + " B"), elapsed); X = X.NextState(Input.GetButton(playerPrefix + " X"), elapsed); Y = Y.NextState(Input.GetButton(playerPrefix + " Y"), elapsed); // D-Pad DPad = DPad.NextState(Input.GetButton(playerPrefix + " DPadUp"), Input.GetButton(playerPrefix + " DPadDown"), Input.GetButton(playerPrefix + " DPadLeft"), Input.GetButton(playerPrefix + " DPadRight"), elapsed); // Deadzone that shit const float DeadZone = 0.1f; var left = new Vector2(Input.GetAxisRaw(playerPrefix + " LeftStick X"), Input.GetAxisRaw(playerPrefix + " LeftStick Y") * -1); var right = new Vector2(Input.GetAxisRaw(playerPrefix + " RightStick X"), Input.GetAxisRaw(playerPrefix + " RightStick Y") * -1); if (Math.Abs(left.x) < DeadZone) { left.x = 0; } else { left.x = (left.x - DeadZone * Math.Sign(left.x)) / (1 - DeadZone); } if (Math.Abs(left.y) < DeadZone) { left.y = 0; } else { left.y = (left.y - DeadZone * Math.Sign(left.y)) / (1 - DeadZone); } if (Math.Abs(right.x) < DeadZone) { right.x = 0; } else { right.x = (right.x - DeadZone * Math.Sign(right.x)) / (1 - DeadZone); } if (Math.Abs(right.y) < DeadZone) { right.y = 0; } else { right.y = (right.y - DeadZone * Math.Sign(right.y)) / (1 - DeadZone); } // Thumbsticks LeftStick = LeftStick.NextState(left, Input.GetButton(playerPrefix + " LeftStick Press"), elapsed); RightStick = LeftStick.NextState(right, Input.GetButton(playerPrefix + " RightStick Press"), elapsed); } }
public void Update(TimeSpan elapsed) { if (!Connected) { return; } State state = Controller.GetState(); var gamepadState = state.Gamepad; // Sadly we can't really use the packet information because everything is temporal // Even if everything stayed the same, that's valid data (elapsed time goes up, etc.) // Vibration if (leftMotor.Active) { leftMotor = UpdateMotor(leftMotor, elapsed); } if (rightMotor.Active) { rightMotor = UpdateMotor(rightMotor, elapsed); } if (leftMotor.LastAmount != leftMotor.CurrentAmount || rightMotor.LastAmount != rightMotor.CurrentAmount) { Controller.SetVibration(new Vibration { LeftMotorSpeed = (ushort)(leftMotor.CurrentAmount * ushort.MaxValue), RightMotorSpeed = (ushort)(rightMotor.CurrentAmount * ushort.MaxValue) }); } // Shoulders LeftShoulder = LeftShoulder.NextState((gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0, elapsed); RightShoulder = RightShoulder.NextState((gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0, elapsed); // Triggers LeftTrigger = LeftTrigger.NextState(gamepadState.LeftTrigger / (float)byte.MaxValue, elapsed); RightTrigger = RightTrigger.NextState(gamepadState.RightTrigger / (float)byte.MaxValue, elapsed); // Buttons Start = Start.NextState((gamepadState.Buttons & GamepadButtonFlags.Start) != 0); Back = Back.NextState((gamepadState.Buttons & GamepadButtonFlags.Back) != 0); A = A.NextState((gamepadState.Buttons & GamepadButtonFlags.A) != 0, elapsed); B = B.NextState((gamepadState.Buttons & GamepadButtonFlags.B) != 0, elapsed); X = X.NextState((gamepadState.Buttons & GamepadButtonFlags.X) != 0, elapsed); Y = Y.NextState((gamepadState.Buttons & GamepadButtonFlags.Y) != 0, elapsed); // D-Pad DPad = DPad.NextState((gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0, (gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0, elapsed); // Thumb sticks LeftStick = LeftStick.NextState( Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.GamepadLeftThumbDeadZone), (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0, elapsed); RightStick = RightStick.NextState( Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.GamepadRightThumbDeadZone), (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0, elapsed); }
/// <summary> /// Serves as a hash function for a <see cref="osuTK.Input.GamePadState"/> object. /// </summary> /// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a /// hash table.</returns> public override int GetHashCode() { return (ThumbSticks.GetHashCode() ^ Buttons.GetHashCode() ^ DPad.GetHashCode() ^ IsConnected.GetHashCode()); }
// Use this for initialization void Start() { _Instance = this; DPadOutput = new Vector3(); }
/// <summary> /// Determine if a button was pressed. /// </summary> /// <param name="button">The <see cref="DPad"/> button to check.</param> /// <returns></returns> public static bool IsPressed(DPad button) { int i = (int)button; return(!_ports1[i].Read()); }
void Start() { Instance = this; }
public override void OnUpdate() { Random rnd = new Random(); Program.labelDebug.BackColor = scene.BackColor; Buttons buttons = Gamepad.GetButtons(Player.First); Triggers triggers = Gamepad.GetTriggers(Player.First); Sticks sticks = Gamepad.GetSticks(Player.First); DPad dPad = Gamepad.GetDPad(Player.First); Program.labelDebug.Text = $"Current Game Tick: {this.Tick}\r\nLS_X: {sticks.LeftStickAxisX:F2} | LS_Y: {sticks.LeftStickAxisY:F2} | RS_X: {sticks.RightStickAxisX:F2} | RS_Y: {sticks.RightStickAxisY:F2} | LT: {triggers.LT:F2} | RT: {triggers.RT:F2}\r\nButtons: A: {buttons.A} | B: {buttons.B} | X: {buttons.X} | Y: {buttons.Y} | LB: {buttons.LB} | RB: {buttons.RB} | BACK: {buttons.Back} | START: {buttons.Menu} | LS: {buttons.LeftStick} | RS: {buttons.RightStick}\r\nDPad: Up {dPad.Up} | Right: {dPad.Right} | Down: {dPad.Down} | Left: {dPad.Left}\r\nKeyboard: {Keyboard.GetKeys().ToString()}"; obj1.X += (int)(obj1.InitialSpeed * sticks.LeftStickAxisX); obj1.Y += (int)(obj1.InitialSpeed * sticks.LeftStickAxisY * -1); obj2.X += (int)(obj2.InitialSpeed * sticks.RightStickAxisX); obj2.Y += (int)(obj2.InitialSpeed * sticks.RightStickAxisY * -1); if (buttons.Back) { GameApplication.Exit(0); } Keys mod = Keyboard.GetKeyModifiers(); if (Keyboard.IsKeyDown(Keys.W)) { if (!obj2.IsAnimated) { obj2.PlayAnimation("anim"); } if (Keyboard.IsKeyDown(Keys.ControlKey)) { obj1.Y -= (int)(obj1.InitialSpeed * 0.5f); } else { obj1.Y -= obj1.InitialSpeed; } } if (Keyboard.IsKeyDown(Keys.S)) { if (!obj2.IsAnimated) { obj2.PlayAnimation("anim"); } if (Keyboard.IsKeyDown(Keys.ControlKey)) { obj1.Y += (int)(obj1.InitialSpeed * 0.5f); } else { obj1.Y += obj1.InitialSpeed; } } if (Keyboard.IsKeyDown(Keys.A)) { if (!obj2.IsAnimated) { obj2.PlayAnimation("anim"); } if (Keyboard.IsKeyDown(Keys.ControlKey)) { obj1.X -= (int)(obj1.InitialSpeed * 0.5f); } else { obj1.X -= obj1.InitialSpeed; } } if (Keyboard.IsKeyDown(Keys.D)) { if (!obj2.IsAnimated) { obj2.PlayAnimation("anim"); } if (Keyboard.IsKeyDown(Keys.ControlKey)) { obj1.X += (int)(obj1.InitialSpeed * 0.5f); } else { obj1.X += obj1.InitialSpeed; } } if (GameApplication.GetGameTick() == 100) { IsTinting = true; } if (IsTinting && GameApplication.GetGameTick() < 130 && GameApplication.GetGameTick() > 100) { TintVal += 0.05f; if (TintVal < 1.0f) { scene.TintScene(Color.Black, TintVal); } else { scene.TintScene(Color.Black, 1.0f); IsTinting = false; } } if (!IsTinting && GameApplication.GetGameTick() > 130) { TintVal -= 0.05f; if (TintVal > 0.0f) { scene.TintScene(Color.Black, TintVal); } else { scene.TintScene(Color.Black, 0.0f); } } label.LabelColor = Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)); rectangleObject.FillColor = Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255)); }
void Awake() { _Instance = this; }