public void Update(GameTime gameTime)
    {
        previousMouseState    = currentMouseState;
        previousKeyboardState = currentKeyboardState;
        previousGamePadState  = (GamePadState[])currentGamePadState.Clone();
        //previousJoyState = currentJoyState;

        currentMouseState    = Mouse.GetState();
        currentKeyboardState = Keyboard.GetState();

        foreach (PlayerIndex index in Enum.GetValues(typeof(PlayerIndex)))
        {
            currentGamePadState[(int)index] = GamePad.GetState(index);
        }

        if (RumbleDuration > 0)
        {
            GamePadVibration(PlayerIndex.One, leftMotor, rightMotor);
            rumbleDuration -= (float)gameTime.ElapsedGameTime.TotalSeconds;
        }

        if (!currentGamePadState[0].IsConnected && enableControllers && joystick == null)
        {
            JoystickPing -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (JoystickPing < 0)
            {
                JoystickPing = JoystickPingDuration;
                var th = new Thread(GenericControllerConnection);
                th.Start();
#if DEBUG
                Console.WriteLine("A new thread has been created!");
#endif
            }
        }
        else if (joystick != null && enableControllers)
        {
            joystick.Poll();
#if DEBUG
            Console.WriteLine("Polling Joystick...");
#endif
            try
            {
                JoystickState state = joystick.GetCurrentState();
                currentJoyState = joystick.GetCurrentState();
                bool[] button = state.Buttons;
                int[]  hats   = state.PointOfViewControllers;
                Console.WriteLine("[{0}]", string.Join(", ", hats));
            }
            catch (Exception)
            {
#if DEBUG
                Console.WriteLine("Oops, the controller disconnected!");
#endif
                joystick = null;
            }
        }
    }
示例#2
0
 public void RefreshState()
 {
     if (padConnected)
     {
         PadState = Pad.GetCurrentState();
     }
     else
     {
         PadState = new DI.JoystickState();
     }
 }
示例#3
0
        public bool ButtonAPressed()
        {
            bool pressed = false;

            if (padConnected)
            {
                PadState = Pad.GetCurrentState();
                if (PadState.Buttons[0])
                {
                    pressed = true;
                }
            }
            return(pressed);
        }
示例#4
0
 public byte[] Draw(DI.JoystickState state)
 {
     return(imageArray);
 }
        /// <summary>Initialises the joystick.</summary>
        private void InitialiseJoystick()
        {
            List<DI.Joystick> joysticks = GetAttachedJoysticks();

            if(ControllerIndex < joysticks.Count)
            {
                _joystick = joysticks[ControllerIndex];
                _joystickState = _joystick.GetCurrentState();

                System.Diagnostics.Debug.WriteLine("Using joystick: " + _joystick.Information.InstanceName);
            }

            _joystickConnected = (_joystickState != null);
        }
示例#6
0
        public byte[] Draw(DI.JoystickState state)
        {
            workBmp = new Bitmap(pad);
            graph   = Graphics.FromImage(workBmp);
            graph.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;

            for (int i = 0; i < 8; i++)
            {
                if (state.Buttons[i])
                {
                    graph.DrawImage(buttons[i].BMP, new Point(buttons[i].X, buttons[i].Y));
                }
            }

            int slx = 65 + ((state.X - 32767) / 1310);
            int sly = 121 + ((state.Y - 32767) / 1310);

            int srx = 281 + ((state.RotationX - 32767) / 1310);
            int sry = 202 + ((state.RotationY - 32767) / 1310);

            Color pixel;

            for (int i = 0; i < (52); i++)
            {
                for (int j = 0; j < 52; j++)
                {
                    pixel = trace.GetPixel(i, j);
                    trace.SetPixel(i, j, Color.FromArgb((byte)Math.Floor(pixel.A / 1.1), pixel));
                }
            }
            traceGraph = Graphics.FromImage(trace);
            traceGraph.DrawEllipse(new Pen(traceBrush), slx - 65, sly - 121, 10, 10);

            graph.DrawImage(sl, new Point(slx, sly));
            graph.DrawImage(trace, new Point(slx, sly));
            graph.DrawImage(sr, new Point(srx, sry));

            if (state.Z <= 32500)
            {
                if (state.Z <= 3000)
                {
                    graph.DrawImage(tl0, new Point(90, 8));
                    graph.DrawImage(tr2, new Point(368, 8));
                }
                else
                {
                    graph.DrawImage(tl0, new Point(90, 8));
                    graph.DrawImage(tr1, new Point(368, 8));
                }
            }
            else if (state.Z >= 33000)
            {
                if (state.Z >= 63000)
                {
                    graph.DrawImage(tr0, new Point(368, 8));
                    graph.DrawImage(tl2, new Point(90, 8));
                }
                else
                {
                    graph.DrawImage(tr0, new Point(368, 8));
                    graph.DrawImage(tl1, new Point(90, 8));
                }
            }
            else
            {
                graph.DrawImage(tr0, new Point(368, 8));
                graph.DrawImage(tl0, new Point(90, 8));
            }

            switch (state.PointOfViewControllers[0])
            {
            case 0:
                graph.DrawImage(du, new Point(136, 178));
                break;

            case 4500:
                graph.DrawImage(dru, new Point(136, 178));
                break;

            case 9000:
                graph.DrawImage(dr, new Point(136, 178));
                break;

            case 13500:
                graph.DrawImage(drd, new Point(136, 178));
                break;

            case 18000:
                graph.DrawImage(dd, new Point(136, 178));
                break;

            case 22500:
                graph.DrawImage(dld, new Point(136, 178));
                break;

            case 27000:
                graph.DrawImage(dl, new Point(136, 178));
                break;

            case 31500:
                graph.DrawImage(dlu, new Point(136, 178));
                break;

            default:
                break;
            }

            bmpData = workBmp.LockBits(new Rectangle(0, 0, workBmp.Width, workBmp.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
            Marshal.Copy(bmpData.Scan0, imageArray, 0, bmpData.Stride * workBmp.Height);
            workBmp.UnlockBits(bmpData);
            return(imageArray);
        }