Beispiel #1
0
        /// <summary>
        /// Function to draw a spray on the screen.
        /// </summary>
        /// <param name="device">Controller to use for the spray.</param>
        /// <param name="index">Index of the controller.</param>
        private void DrawSpray(IGorgonGamingDevice device, int index)
        {
            SprayCan state = _sprayStates[index];

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

            GorgonRange throttleRange = device.Info.AxisInfo[GamingDeviceAxis.RightTrigger].Range;

            // Find out if we're spraying.
            if (device.Axis[GamingDeviceAxis.RightTrigger].Value > throttleRange.Minimum)
            {
                if ((!state.IsActive) && (!state.NeedReset))
                {
                    // Convert the throttle value to a unit value.
                    float throttleUnit = ((float)(device.Axis[GamingDeviceAxis.RightTrigger].Value - throttleRange.Minimum) / throttleRange.Range);

                    // Set up the spray state.
                    state.Position        = state.Origin;
                    state.Amount          = throttleRange.Range / 2.0f;
                    state.Time            = throttleUnit * 10.0f;
                    state.VibrationAmount = device.Info.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);
        }