Beispiel #1
0
        public void Update(int ranking_, float steeringValue_ = 0, bool braking_ = false)
        {
            // Updates the vehicle
            // ================

            foreach (Tyre t in m_vehicleTyres)
            {
                t.UpdateTyre(ranking_, steeringValue_, braking_);
                t.UpdateFriction();
            }

            foreach (Tyre t in m_vehicleTyres)
            {
                t.UpdateDrive();

                if (t.IsPowered())
                {
                    if (t.GetBody().LinearVelocity.Length() > 3.0f)
                    {
                        GraphicsHandler.StartFireTrail(t.GetPositionDisplay());
                    }
                    else if (t.GetBody().LinearVelocity.Length() > 2.0f)
                    {
                        GraphicsHandler.StartDriveTrail(t.GetPositionDisplay());
                    }
                    else if (t.GetBody().LinearVelocity.Length() > 0.0f)
                    {
                        GraphicsHandler.StartBrakeTrail(t.GetPositionDisplay());
                    }
                    else if (t.GetBody().LinearVelocity.Length() < 0.0f)
                    {
                        GraphicsHandler.StartBrakeTrail(t.GetPositionDisplay());
                    }
                }

                float lockAngle       = Util.DegreesToRadians(20);
                float turnSpeedPerSec = Util.DegreesToRadians(320);
                float turnPerTimeStep = turnSpeedPerSec / 60;
                float desiredAngle    = steeringValue_ * lockAngle;
                float angleNow        = m_frontLeftJoint.JointAngle;
                float angleToTurn     = desiredAngle - angleNow;
                angleToTurn = FarseerPhysics.Common.MathUtils.Clamp(angleToTurn, -turnPerTimeStep, turnPerTimeStep);
                float newAngle = angleNow + angleToTurn;

                if (desiredAngle > 0.25)
                {
                    GraphicsHandler.StartSkidMarks(t.GetPositionDisplay());
                }

                m_frontLeftJoint.SetLimits(newAngle, newAngle);
                m_frontRightJoint.SetLimits(newAngle, newAngle);

                t.UpdateSprites();

                // AUDIO
                if (!braking_)
                {
                    carbrake.Stop(); //ADDED
                    go.Play();       // ADDED
                }
                else
                {
                    go.Stop();       //ADDED
                    carbrake.Play(); // ADDED
                }
            }

            Debug.AddText("Body position D: " + FarseerPhysics.ConvertUnits.ToDisplayUnits(m_vehicleBody.GetPosition()).ToString(), new Vector2(10, 300));
            Debug.AddText("Body position S: " + m_vehicleBody.GetPosition().ToString(), new Vector2(10, 320));
            Debug.AddText("FL position D: " + FarseerPhysics.ConvertUnits.ToDisplayUnits(m_vehicleTyres[0].GetPosition()).ToString(), new Vector2(10, 360));
            Debug.AddText("FL position S: " + m_vehicleTyres[0].GetPosition().ToString(), new Vector2(10, 380));
            Debug.AddText("FL rotation: " + Util.RadiansToDegrees(m_frontLeftJoint.JointAngle).ToString(), new Vector2(10, 400));
            Debug.AddText("FR position D: " + FarseerPhysics.ConvertUnits.ToDisplayUnits(m_vehicleTyres[1].GetPosition()).ToString(), new Vector2(10, 420));
            Debug.AddText("FR position S: " + m_vehicleTyres[1].GetPosition().ToString(), new Vector2(10, 440));
            Debug.AddText("FR rotation: " + Util.RadiansToDegrees(m_frontRightJoint.JointAngle).ToString(), new Vector2(10, 460));
            m_vehicleBody.UpdateSprites();
        }