Пример #1
0
        /// <summary>
        /// Function to draw a spray on the screen.
        /// </summary>
        /// <param name="joystick">Joystick to use for the spray.</param>
        /// <param name="index">Index of the joystick.</param>
        private void DrawSpray(GorgonJoystick joystick, int index)
        {
            SprayCan state = _sprayStates[index];

            // Update the origin of the spray.
            state.Origin = _stickPosition[index];

            // Find out if we're spraying.
            if (joystick.Throttle > joystick.Capabilities.ThrottleAxisRange.Minimum)
            {
                if ((!state.IsActive) && (!state.NeedReset))
                {
                    // Convert the throttle value to a unit value.
                    float throttleUnit = ((float)(joystick.Throttle - joystick.Capabilities.ThrottleAxisRange.Minimum) / joystick.Capabilities.ThrottleAxisRange.Range);

                    // Set up the spray state.
                    state.Position        = state.Origin;
                    state.Amount          = joystick.Capabilities.ThrottleAxisRange.Range / 2.0f;
                    state.Time            = throttleUnit * 10.0f;
                    state.VibrationAmount = joystick.Capabilities.VibrationMotorRanges[1].Maximum;
                    state.SprayAlpha      = (throttleUnit * 239.0f) + 16;
                    state.IsActive        = true;
                }
            }
            else
            {
                state.IsActive = false;
            }

            if (!state.IsActive)
            {
                return;
            }

            // Update the state spray effect.
            state.Update();
            _surface.DrawPoint(Point.Round(state.Position), state.SprayColor, state.SprayPointSize);
        }
Пример #2
0
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Form.Load" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            try
            {
                // Load the XInput plug-in assembly.
                Gorgon.PlugIns.LoadPlugInAssembly(Program.PlugInPath + "Gorgon.Input.XInput.dll");

                // Create our factory.
                _factory = GorgonInputFactory.CreateInputFactory("GorgonLibrary.Input.GorgonXInputPlugIn");

                // Ensure that we have and XBox controller to work with.
                if (_factory.JoystickDevices.Count == 0)
                {
                    GorgonDialogs.ErrorBox(this, "No XBox controllers were found on this system.\nThis example requires an XBox controller.");
                    Gorgon.Quit();
                    return;
                }

                // Enumerate the active joysticks.  We'll only take 3 of the 4 available xbox controllers.
                _joystick      = new GorgonJoystick[3];
                _stickPosition = new PointF[_joystick.Count];
                _sprayStates   = new SprayCan[_joystick.Count];

                for (int i = 0; i < _joystick.Count; i++)
                {
                    var joystick = _factory.CreateJoystick(this, _factory.JoystickDevices[i].Name);

                    // Set a dead zone on the joystick.
                    // A dead zone will stop input from the joystick until it reaches the outside
                    // of the specified coordinates.
                    joystick.DeadZone.X          = new GorgonRange(joystick.Capabilities.XAxisRange.Minimum / 4, joystick.Capabilities.XAxisRange.Maximum / 4);
                    joystick.DeadZone.Y          = new GorgonRange(joystick.Capabilities.YAxisRange.Minimum / 4, joystick.Capabilities.YAxisRange.Maximum / 4);
                    joystick.DeadZone.SecondaryX = new GorgonRange(joystick.Capabilities.XAxisRange.Minimum / 128, joystick.Capabilities.XAxisRange.Maximum / 128);
                    joystick.DeadZone.SecondaryY = new GorgonRange(joystick.Capabilities.YAxisRange.Minimum / 128, joystick.Capabilities.YAxisRange.Maximum / 128);

                    _joystick[i] = joystick;

                    // Start at a random spot.
                    _stickPosition[i] = new Point(GorgonRandom.RandomInt32(64, panelDisplay.ClientSize.Width - 64), GorgonRandom.RandomInt32(64, panelDisplay.ClientSize.Height - 64));

                    // Turn off spray for all controllers.
                    _sprayStates[i] = new SprayCan(joystick, i);
                }

                // Check for connected controllers.
                while (!_joystick.Any(item => item.IsConnected))
                {
                    if (MessageBox.Show(this,
                                        "There are no XBox controllers connected.\nPlease plug in an XBox controller and click OK.",
                                        "No Controllers", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.Cancel)
                    {
                        continue;
                    }

                    Gorgon.Quit();
                    return;
                }

                // Get the graphics interface for our panel.
                _surface = new DrawingSurface(panelDisplay);

                // Set up our idle loop.
                Gorgon.ApplicationIdleLoopMethod += Idle;
            }
            catch (Exception ex)
            {
                // We do this here instead of just calling the dialog because this
                // function will send the exception to the Gorgon log file.
                GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex));
                Gorgon.Quit();
            }
        }