public void Update(AnalogState state, ThumbStick thumbStick, FrameDetails frame)
        {
            // Speed is pixels per second
            var    speed = MovementConfiguration.Speed * frame.TimeDelta / 1000d;
            var    accel = MovementConfiguration.Acceleration;
            double x, y;

            if (accel != 0d && accel != 1d)
            {
                var angle    = state.Angle;
                var distance = Math.Pow(1d + state.Distance, accel) - 1d;
                x = distance * Math.Cos(angle);
                y = -distance *Math.Sin(angle);
            }
            else
            {
                x = state.X;
                y = -state.Y;
            }

            if (MovementConfiguration.InvertX)
            {
                x = -x;
            }

            if (MovementConfiguration.InvertY)
            {
                y = -y;
            }

            MovementActuator.Move(x * speed, y * speed);
        }
Example #2
0
    void KuunteleLiiketta2(AnalogState hiirenTila)
    {
        int kohtausNumero = 0;

        foreach (PhysicsObject sana in tuoteLista)
        {
            //string apu = sana.ToString();
            if (Mouse.IsCursorOn(sana))
            {
                kohtausNumero = tuoteLista.IndexOf(sana);
                break;
            }
        }
        switch (kohtausNumero)
        {
        case 0:
            elamansuola.Position = Mouse.PositionOnWorld;

            MessageDisplay.Add("Käytä ensi kerralla Himalajan suolaa");
            MessageDisplay.MaxMessageCount = 0;

            break;

        case 1:
            hksininen.Position = Mouse.PositionOnWorld;

            MessageDisplay.Add("Vähä kyrsää... Brus suomalaista!");
            MessageDisplay.MaxMessageCount = 0;
            break;
        }
    }
Example #3
0
    void HeitaHiirella(AnalogState state)
    {
        //MessageDisplay.RealTime = true;
        //MessageDisplay.Add( String.Format( "({0}, {1})", Mouse.PositionOnScreen.X, Mouse.PositionOnScreen.Y ) );

        if (onHeittamassa)
        {
            pallo.Position = Mouse.PositionOnWorld;
            LisaaLiike(state.MouseMovement);
        }
    }
Example #4
0
 public void TestAnalogLoopChange(AnalogState input)
 {
     if (input.state < 25600)
     {
         input.state++;
     }
     else
     {
         Debug.Log("Current state: " + input.state.ToString());
         Debug.Log("Finished testing");
     }
 }
Example #5
0
 /// <summary>
 /// Näyttää valinnan päävalikossa punaisella.
 /// </summary>
 /// <param name="hiirenTila"></param>
 private void ValikossaLiikkuminen(AnalogState hiirenTila)
 {
     foreach (Label kohta in valikonKohdat)
     {
         if (Mouse.IsCursorOn(kohta))
         {
             kohta.TextColor = Color.BloodRed;
         }
         else
         {
             kohta.TextColor = Color.Black;
         }
     }
 }
Example #6
0
    void OnMouseMove(AnalogState anaSt)
    {
        GameObject hoverObject = GetObjectAt(Mouse.PositionOnScreen);

        if (activeCell != null && hoverObject != activeCell)
        {
            activeCell.Color = activeCellOrigColor;
            activeCell       = null;
        }

        if (activeCell == null && hoverObject != null)
        {
            activeCellOrigColor = hoverObject.Color;
            activeCell          = hoverObject;
            hoverObject.Color   = Color.Lighter(hoverObject.Color, 100);
        }
    }
Example #7
0
        /*
         * Creates the serial controller.
         */
        public RobloxUltimateDrivingSerialController()
        {
            // Get the input devices.
            this.Keyboard = Keyboard.GetInstance();
            this.Gamepad  = Gamepad.GetInstance();

            // Create the signals.
            this.BrakeSignal           = new KeyboardPWMSignal(VirtualKeyCode.VK_B, THROTTLE_KEYBOARD_FREQUENCY);
            this.BrakeSignal.DutyCycle = 0;

            // Create the state controllers.
            this.TurnSignalStateController = new AnalogState(3, 1, (newState, previousState) =>
            {
                if ((newState == 1 && previousState == 0) || newState == 0)
                {
                    this.Keyboard.SendKeyPress(VirtualKeyCode.VK_Z);
                }
                else if ((newState == 1 && previousState == 2) || newState == 2)
                {
                    this.Keyboard.SendKeyPress(VirtualKeyCode.VK_C);
                }
            });
            this.ShifterStateController = new AnalogState(3, 1, (newState, previousState) =>
            {
                // Change the reversing state.
                if (newState == 0)
                {
                    this.Reversing = true;
                }
                else
                {
                    this.Reversing = false;
                }

                // Press the parking key.
                if ((newState == 1 && previousState == 2) || newState == 2)
                {
                    this.Keyboard.SendKeyPress(VirtualKeyCode.VK_P);
                }
            });
        }
Example #8
0
    /// <summary>
    /// Hoidetaan tähtääminen
    /// Määritetään uusi Vector suunta, johon lasketaan pelaajan aseen ja hiiren välinen suunta.
    /// </summary>
    /// <param name="hiirenliike">hiirenliike</param>
    public void Tahtaa(AnalogState hiirenliike)
    {
        //MessageDisplay.Add(Mouse.PositionOnWorld.X + "");
        if (pelaajaKatsooVasemmalle == false && Mouse.PositionOnScreen.X < 0)
        {
            pelaaja.MirrorImage();
            pelaajanAse.FlipImage();
            pelaajanAse.X           = -10;
            pelaajaKatsooVasemmalle = true;
        }
        else if (pelaajaKatsooVasemmalle == true && Mouse.PositionOnScreen.X > 0)
        {
            pelaaja.MirrorImage();
            pelaajanAse.FlipImage();
            pelaajanAse.X           = 10;
            pelaajaKatsooVasemmalle = false;
        }

        Vector suunta = (Mouse.PositionOnWorld - pelaajanAse.AbsolutePosition).Normalize();

        pelaajanAse.Angle = suunta.Angle;
    }
        public void Update(AnalogState state, ThumbStick thumbStick, FrameDetails frame)
        {
            var x        = Configuration.InvertX ? -state.X : state.X;
            var y        = Configuration.InvertY ? state.Y : -state.Y;
            var distance = Math.Sqrt(x * x + y * y);

            if (distance <= Configuration.MinRadius)
            {
                memory.Clear();
                distance = 0d;
            }
            else
            {
                distance = (distance - Configuration.MinRadius) / (1d - Configuration.MinRadius);
            }

            var angle = Math.Atan2(y, x);

            memory.Enqueue(new AngleData(angle));
            var avgCos = 0d;
            var avgSin = 0d;

            foreach (var item in memory)
            {
                avgCos += item.Cos;
                avgSin += item.Sin;
            }

            avgCos /= memory.Count;
            avgSin /= memory.Count;
            var avgAngle = Math.Atan2(avgSin, avgCos);

            while (memory.Count > Configuration.Smoothing / frame.FrameTime)
            {
                memory.Dequeue();
            }

            RadialActuator.Update((avgAngle * 180d / Math.PI + 90d) % 360d, distance);
        }
 public void SetWeight(AnalogState input)
 {
     SetWeight(input.state);
 }
Example #11
0
 public void TestAnalogChange(AnalogState input)
 {
     Debug.Log("Current state: " + input.state.ToString());
     Debug.Log("Previous state: " + input.previous_state.ToString());
 }
Example #12
0
 void tahtaa(AnalogState hiirenliike)
 {
     Vector suunta = (Mouse.PositionOnWorld - pelaaja.AbsolutePosition).Normalize();
     pelaajan1ase.Angle = suunta.Angle;
 }
Example #13
0
 void hiirenliikutus(AnalogState hiirenTila)
 {
     cursor.X = Mouse.PositionOnWorld.X;
     cursor.Y = Mouse.PositionOnWorld.Y;
 }
        /*
         * Handles the serial handler.
         */
        public void HandleInputs()
        {
            try
            {
                // Create and open the port.
                var port = new SerialPort("COM" + this.Port, 9600, Parity.None, 8, StopBits.One);
                port.Open();
                Console.WriteLine("Opened on port COM" + this.Port);

                // Create the controllers.
                if (this.Controllers == null)
                {
                    this.Controllers = new List <BaseSerialController>()
                    {
                        null,
                        new RobloxUltimateDrivingSerialController(),
                    };
                    this.AnalogInputNames = new List <string>()
                    {
                        "Mode Selector",
                        "Steering Wheel",
                        "Right Pedal",
                        "Left Pedal",
                        "Left Shifter",
                        "Right Shifter",
                    };
                    this.ControllerNames = new List <string>()
                    {
                        null,
                        "Roblox Ultimate Driving",
                    };
                    this.LastAnalogInputs = new List <byte>()
                    {
                        0, 0, 0, 0, 0, 0
                    };
                }

                // Create the analog input mapper.
                var analogMappers = new List <AnalogMapper>();
                foreach (var data in this.AnalogInputs)
                {
                    analogMappers.Add(AnalogMapper.FromData(data));
                }

                // Create the mode selector.
                var currentController           = 0;
                var modeSelectorStateController = new AnalogState(6, 0, (newState, previousState) =>
                {
                    currentController = newState;

                    // Start the new controller.
                    if (newState < this.Controllers.Count && this.Controllers[newState] != null)
                    {
                        Console.WriteLine("Using controls for " + this.ControllerNames[newState]);
                        this.Controllers[newState].Start();
                    }
                    else
                    {
                        Console.WriteLine("Disabled controls");
                    }

                    // Stop the previous controller.
                    if (previousState < this.Controllers.Count && this.Controllers[previousState] != null)
                    {
                        this.Controllers[previousState].Stop();
                    }
                });

                // Start accepting inputs.
                while (true)
                {
                    // Read the line.
                    var line = port.ReadLine();
                    try
                    {
                        // Handle the inputs.
                        if (line.Length >= 4 && line.Contains(","))
                        {
                            var inputType = line[0];
                            if (inputType == 'A')
                            {
                                var channel = int.Parse(line.Substring(1).Split(',')[0]);
                                var input   = int.Parse(line.Substring(1).Split(',')[1]);
                                if (channel < analogMappers.Count)
                                {
                                    var mapper           = analogMappers[channel];
                                    var initiallyEnabled = mapper.MinimumRangeMet();
                                    var mappedValue      = mapper.GetValue(input);
                                    if (mapper.MinimumRangeMet())
                                    {
                                        if (channel == 0)
                                        {
                                            modeSelectorStateController.SetValue(mappedValue);
                                        }
                                        else
                                        {
                                            // Send the input.
                                            this.LastAnalogInputs[channel] = mappedValue;
                                            if (currentController < this.Controllers.Count && this.Controllers[currentController] != null)
                                            {
                                                this.Controllers[currentController].HandleInput("A" + channel + "," + mappedValue);
                                                if (!initiallyEnabled && this.AnalogInputNames[channel] != null)
                                                {
                                                    Console.WriteLine(this.AnalogInputNames[channel] + " is now active.");
                                                }
                                            }

                                            // Reset the pedals if both are down.
                                            if ((channel == 2 || channel == 3) && (this.LastAnalogInputs[2] == 255 && this.LastAnalogInputs[3] == 255))
                                            {
                                                Console.WriteLine("Resetting pedals.");
                                                analogMappers[2].Reset();
                                                analogMappers[3].Reset();
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if (currentController < this.Controllers.Count && this.Controllers[currentController] != null)
                                {
                                    this.Controllers[currentController].HandleInput(line);
                                }
                            }
                        }
                    }
                    catch (FormatException)
                    {
                    }
                }
            }
            catch (IOException)
            {
            }
            catch (InvalidOperationException)
            {
            }
            finally
            {
                if (this.Controllers != null)
                {
                    foreach (var controller in this.Controllers)
                    {
                        if (controller != null)
                        {
                            controller.Stop();
                        }
                    }
                }
            }
        }
Example #15
0
File: bbd.cs Project: EA99/sejypeli
 //ht=hiirentila
 void osoitin(AnalogState ht)
 {
 }
Example #16
0
 private void MuutaPainovoimaa(AnalogState state)
 {
     Gravity = 1000 * state.StateVector;
 }
Example #17
0
        /// <summary>
        /// Tähdätään puhelimen kallistuksen mukaan.  30 asteen kallistuksella taso on vaakassa.
        /// </summary>
        /// <param name="s"></param>
        private void TahtaaAccel(AnalogState s)
        {
            double kulma = s.StateVector.Y * 120 + 30;

            maila.Tavoite = Angle.FromDegrees(kulma);
        }
 public void Press(AnalogState input)
 {
     Press(input.state);
 }
Example #19
0
    public void movePlayerAnalog(AnalogState al, PhysicsObject player)
    {
        double xPos = al.StateVector.X;
        double yPos = al.StateVector.Y;
        Vector pPushVector = new Vector((xPos) * PLAYER_SPEED_X.X, (yPos) * PLAYER_SPEED_Y.Y);
        player.Push(pPushVector);

        double maxVibration = 0.15;
        double maxBias = 0.5;

        double prcBias = (0.5 * Math.Abs((xPos + yPos / 2))) +
                         (0.5 * Math.Max(0, Math.Min(1, (1 - Math.Abs((player.Velocity.Magnitude / 100))))));

        //Bias the control
        double rightControllerVibr = ((maxVibration / 2) - ((maxVibration / 2 * maxBias) * xPos)) * prcBias;
        double leftControllerVibr = ((maxVibration / 2) + ((maxVibration / 2 * maxBias) * xPos)) * prcBias;

        if (((ControllerOne.GetType()) == typeof(GamePad)) && vibrateEnabled)
        {
            GamePad gp = ControllerOne as GamePad;
            gp.Vibrate(leftControllerVibr, rightControllerVibr, 0, 0, 0.1);
        }

        //player.Velocity = pPushVector;
    }
Example #20
0
    void Tahtaa(AnalogState hiirenLiike)
    {
        Vector suunta = (Mouse.PositionOnWorld - pelaaja1.Weapon.AbsolutePosition).Normalize();

        pelaaja1.Weapon.Angle = suunta.Angle;
    }
Example #21
0
 void Tahtaa(AnalogState hiirenliike)
 {
     Vector suunta = (Mouse.PositionOnWorld - Pelaaja.Weapon.AbsolutePosition).Normalize();
     Pelaaja.Weapon.Angle = suunta.Angle;
 }
Example #22
0
    void MouseMoves(AnalogState astate)
    {
        var mp = Mouse.PositionOnWorld;

        foreach (var edge in dragEdges)
        {
            var eps = (EdgeEndpoints)edge.Tag;
            RouteEdgeObject(edge, mp, instance.points[eps.Key]);
        }

        if (activePointIdx >= 0)
        {
            int routeIdx = instance.GetRouteIdxForNode(activePointIdx);
            HighlightOnlyTruck(routeIdx);

            int pidx = GetIndexOfPointUnderMouse();
            List <GameObject> removedEdges = null;
            if (pidx != -1 && pidx != activePointIdx &&
                (pidx == 0 || instance.GetNodeNeighbourCount(pidx) < 2) &&
                instance.ConnectNode(pidx, dragEdges, out removedEdges))
            {
                foreach (var rmEdge in removedEdges)
                {
                    Remove(rmEdge);
                }
                foreach (var edge in dragEdges)
                {
                    var eps = (EdgeEndpoints)edge.Tag;
                    RouteEdgeObject(edge, instance.points[eps.Key], instance.points[eps.Value]);
                }

                RefreshStateAndUpdateDisplays();
                HighlightViolations();

                // The edges are now considered "used"
                dragEdges = new List <GameObject>();
                ActivatePoint(pidx);
            }
        }
        else
        {
            var node = GetIndexOfPointUnderMouse();
            if (node != -1)
            {
                bool       removed      = false;
                List <int> nbrCloneList = new List <int>(instance.GetNodeNeighbours(node));
                foreach (var nbr in nbrCloneList)
                {
                    //var rmEdges = instance.RemoveEdges(node, nbr);
                    //foreach (var rme in rmEdges)
                    //{
                    //    Remove(rme);
                    //    removed = true;
                    //}
                }
                if (removed)
                {
                    RefreshStateAndUpdateDisplays();
                    HighlightViolations();
                }
            }

            var edge     = GetEdgeUnderMouse();
            int routeIdx = instance.GetRouteIdxForEdge(edge);
            if (routeIdx != -1)
            {
                HighlightOnlyTruck(routeIdx);
            }
        }
    }
Example #23
0
    void ValikossaLiikkuminen(AnalogState hiirenTila)
    {
        foreach (Label kohta in valikonKohdat)
        {
            if (Mouse.IsCursorOn(kohta))
            {
                kohta.TextColor = Color.Red;
            }
            else
            {
                kohta.TextColor = Color.Black;
            }

        }
    }
 public void SetVolume(AnalogState input)
 {
     SetVolume(input.state);
 }
 public void SetIntensity(AnalogState input)
 {
     SetIntensity(input.state);
 }