Example #1
0
        // Methods
        public void Run(float deltaTime)
        {
            if (this.vehicleIndex < 0)
            {
                return;
            }
            if (AIRegionsDS == null)
            {
                if (AIRegions == null)
                {
                    return;
                }
                AIRegionsDS = AIRegions.GetDrawingSurface();
            }
            float angleSum = 0f;
            int   agscolor = AIRegionsDS.GetPixel(FloatToInt(Cars[this.vehicleIndex].position.x, eRoundNearest), FloatToInt(Cars[this.vehicleIndex].position.y, eRoundNearest));
            int   i        = 0;

            for (i = 0; i < 16; i += 1)
            {
                if (RegionAngles[i].color == agscolor)
                {
                    angleSum = RegionAngles[i].angle;
                    break;
                }
            }
            this.targetAngle = angleSum;
            float dirAngle     = Cars[this.vehicleIndex].direction.angle();
            float angleBetween = Maths.AnglePiFast(this.targetAngle - Maths.Angle2Pi(dirAngle));
            float steeringDT   = UISteeringAngle * deltaTime * 1.1f;

            if (Maths.AbsF(angleBetween) <= Maths.AbsF(steeringDT))
            {
                Cars[this.vehicleIndex].steeringWheelAngle = 0.0f;
                Cars[this.vehicleIndex].direction.set2(1.0f, 0.0f);
                Cars[this.vehicleIndex].direction.rotate(this.targetAngle);
            }
            else if (angleBetween > 0.0f)
            {
                Cars[this.vehicleIndex].steeringWheelAngle = UISteeringAngle;
            }
            else if (angleBetween < 0.0f)
            {
                Cars[this.vehicleIndex].steeringWheelAngle = -UISteeringAngle;
            }
            else
            {
                Cars[this.vehicleIndex].steeringWheelAngle = 0.0f;
            }
            Cars[this.vehicleIndex].Accelerator = 1.0f;
            Cars[this.vehicleIndex].Brakes      = 0.0f;
        }
        public void run(float deltaTime)
        {
            this.position.addScaled(this.velocity, deltaTime);
            float rot_angle = 0f;

            if (this.driveVelocityValue >= 0.0f)
            {
                rot_angle = this.steering * deltaTime;
            }
            else
            {
                rot_angle = -this.steering * deltaTime;
            }
            this.directionAngle = Maths.Angle2Pi(this.directionAngle + rot_angle);
            this.direction.rotate(rot_angle);
            this.processInteraction(deltaTime);
            float absVelocity      = Maths.AbsF(this.driveVelocityValue);
            float thrustResistance = this.friction * absVelocity + this.brakes;
            float thrustForce      = this.engine * deltaTime;
            float brakeForce       = Maths.MinF(thrustResistance * deltaTime, absVelocity);

            if (this.driveVelocityValue < 0.0f)
            {
                brakeForce = -brakeForce;
            }
            this.driveVelocityValue += thrustForce - brakeForce;
            this.driveVelocity.set(this.direction);
            this.driveVelocity.scale(this.driveVelocityValue);
            this.thrustForceValue = thrustForce;
            this.brakeForceValue  = brakeForce;
            float impactValue = this.impactVelocity.length();

            if (impactValue > 0.0f)
            {
                impactValue = Maths.MaxF(0.0f, impactValue - (this.friction * impactValue * 10.0f + this.brakes) * deltaTime);
                this.impactVelocity.truncate(impactValue);
            }
            this.velocity.set(this.driveVelocity);
            this.velocity.add(this.impactVelocity);
            this.syncCharacter();
        }