internal void Update(CarAgent car, CarAgent[] cars, Road[] roads)
 {
     updateTarget(car);
     updateAngle();
     updateSpeed(roads);
     updatePosition();
 }
        // Constructor
        public CarAgent(int paramId, CarAgent[] cars, World paramWorld)
        {
            // unique ID attribution
            // Well... unique for as long as you only look at existing cars.
            id = paramId;
            flagAbort = false;
            world = paramWorld;

            // Roll of the speed mult.
            int rollSpeedMult = RondPointWindow.rnd.Next(0, 7);
            SpeedMult = 1 - ((rollSpeedMult - 3) / 100); // = 0.97 0.98 0.99 1 1.01 1.02 1.03

            int nbRoad = 0;
            nbRoad = RondPointWindow.rnd.Next(0, 4);

            road = world.roads[nbRoad];
            PosX = road.PosX;
            PosY = road.PosY;
            targetY = PosY;
            targetX = PosX;

            // First Range Calculation for spawn-eligibility on the selected road.
            bool spawnable = false;
            bool pass;

            if (RondPointWindow.carCount > 0)
            {
                while (spawnable == false)
                {
                    pass = true;

                    foreach (CarAgent car in cars)
                    {
                        if (car != null)
                        {
                            if (car.Road == road)
                            {
                                if (DistanceTo(car) < 70)
                                {
                                    pass = false;
                                    break;
                                }
                            }
                        }
                    }

                    if (pass == true)
                    {
                        spawnable = true;
                    }
                    else
                    {
                        break;
                    }
                }

                if (spawnable == false)
                {
                    flagAbort = true;
                }
            }

            switch (road.Id)
            {
                case 1:
                    //left
                    speedX = Road.MaxSpeedRoad;
                    speedY = 0;
                    break;
                case 2:
                    //top
                    speedX = 0;
                    speedY = Road.MaxSpeedRoad;
                    break;
                case 3:
                    //bottom
                    speedX = 0;
                    speedY = -Road.MaxSpeedRoad;
                    break;
                default:
                    //right
                    speedX = -Road.MaxSpeedRoad;
                    speedY = 0;
                    break;
            }

            updateSpeed(paramWorld.roads);
        }
 public void updateTarget(CarAgent car)
 {
     int currentZone = road.getRoadZone(PosX, PosY);
     Road roadDestination;
     switch (currentZone)
     {
         //in middle zone
         case (2):
             if (car.speedX > 0)
             {
                 //left
                 roadDestination = world.roads[0];
                 TargetX = roadDestination.PosX;
                 TargetY = roadDestination.PosY;
             }
             else if (car.speedY > 0)
             {
                 //top
                 roadDestination = world.roads[1];
                 TargetX = roadDestination.PosX;
                 TargetY = roadDestination.PosY;
             }
             else if (car.speedY < 0)
             {
                 //bottom
                 roadDestination = world.roads[2];
                 TargetX = roadDestination.PosX;
                 TargetY = roadDestination.PosY;
             }
             else
             {
                 //right
                 roadDestination = world.roads[3];
                 TargetX = roadDestination.PosX;
                 TargetY = roadDestination.PosY;
             }
             /*if (car.speedX > 0)
             {
                 //left
                 road = world.roads[1];
                 TargetX = road.PosX;
                 TargetY = road.PosY;
             }
             else if (car.speedY > 0)
             {
                 //top
                 road = world.roads[3];
                 TargetX = road.PosX;
                 TargetY = road.PosY;
             }
             else if (car.speedY < 0)
             {
                 //bottom
                 road = world.roads[0];
                 TargetX = road.PosX;
                 TargetY = road.PosY;
             }
             else
             {
                 //right
                 road = world.roads[2];
                 TargetX = road.PosX;
                 TargetY = road.PosY;
             }*/
             break;
         default:
             break;
     }
 }