Ejemplo n.º 1
0
        /// <summary>
        /// Update the Axis.
        /// </summary>
        public override void UpdateFirst()
        {
            base.UpdateFirst();

            LastX = X;
            LastY = Y;

            if (Locked)
            {
                return;
            }

            if (!Enabled)
            {
                X = 0;
                Y = 0;
                return;
            }

            if (ForcedInput)
            {
                return;
            }

            X = 0;
            Y = 0;

            for (int i = 0; i < Joystick.Count; i++)
            {
                foreach (JoyAxis axis in AxesX[i])
                {
                    float a = Input.Instance.GetAxis(axis, i) * 0.01f;
                }
                foreach (JoyAxis axis in AxesY[i])
                {
                    float a = Input.Instance.GetAxis(axis, i) * 0.01f;
                }

                foreach (JoyAxis axis in AxesX[i])
                {
                    float a = Input.Instance.GetAxis(axis, i) * 0.01f;
                    if (Math.Abs(a) >= DeadZone)
                    {
                        if (RemapRange)
                        {
                            if (a > 0)
                            {
                                X += Util.ScaleClamp(a, 0, 1, 0, 1);
                            }
                            else
                            {
                                X += Util.ScaleClamp(a, -1, -0, -1, 0);
                            }
                        }
                        else
                        {
                            X += a;
                        }
                    }
                    if (RoundInput)
                    {
                        X = (float)Math.Round(X, 2);
                    }
                }

                foreach (JoyAxis axis in AxesY[i])
                {
                    float a = Input.Instance.GetAxis(axis, i) * 0.01f;
                    if (Math.Abs(a) >= DeadZone)
                    {
                        if (RemapRange)
                        {
                            if (a > 0)
                            {
                                Y += Util.ScaleClamp(a, 0, 1, 0, 1);
                            }
                            else
                            {
                                Y += Util.ScaleClamp(a, -1, -0, -1, 0);
                            }
                        }
                        else
                        {
                            Y += a;
                        }
                    }
                    if (RoundInput)
                    {
                        Y = (float)Math.Round(Y, 2);
                    }
                }
            }

            foreach (Key k in Keys[Direction.Up])
            {
                if (Input.Instance.KeyDown(k))
                {
                    Y -= 1;
                }
            }
            foreach (Key k in Keys[Direction.Down])
            {
                if (Input.Instance.KeyDown(k))
                {
                    Y += 1;
                }
            }
            foreach (Key k in Keys[Direction.Left])
            {
                if (Input.Instance.KeyDown(k))
                {
                    X -= 1;
                }
            }
            foreach (Key k in Keys[Direction.Right])
            {
                if (Input.Instance.KeyDown(k))
                {
                    X += 1;
                }
            }

            for (int i = 0; i < Joystick.Count; i++)
            {
                foreach (int b in JoyButtons[Direction.Up][i])
                {
                    if (Input.Instance.ButtonDown(b, i))
                    {
                        Y -= 1;
                    }
                }
                foreach (int b in JoyButtons[Direction.Down][i])
                {
                    if (Input.Instance.ButtonDown(b, i))
                    {
                        Y += 1;
                    }
                }
                foreach (int b in JoyButtons[Direction.Left][i])
                {
                    if (Input.Instance.ButtonDown(b, i))
                    {
                        X -= 1;
                    }
                }
                foreach (int b in JoyButtons[Direction.Right][i])
                {
                    if (Input.Instance.ButtonDown(b, i))
                    {
                        X += 1;
                    }
                }
            }

            X = Util.Clamp(X, -1, 1);
            Y = Util.Clamp(Y, -1, 1);

            // Update the buttons.  This makes it easy to read the Axis as buttons for Up, Right, Left, Down.
            Right.UpdateFirst();
            Up.UpdateFirst();
            Left.UpdateFirst();
            Down.UpdateFirst();

            Right.ForceState(false);
            Up.ForceState(false);
            Left.ForceState(false);
            Down.ForceState(false);

            if (X > 0.5f)
            {
                Right.ForceState(true);
            }
            if (X < -0.5f)
            {
                Left.ForceState(true);
            }
            if (Y > 0.5f)
            {
                Down.ForceState(true);
            }
            if (Y < -0.5f)
            {
                Up.ForceState(true);
            }
        }