private bool checkSideHit(Physic.PCar self, List <Physic.PCar> enemies) { double checkRadius = (game.CarHeight + game.CarWidth) * Math.Sqrt(2) * 0.5; double maxAngle = Math.PI / 6; self.setEnginePower(1); for (int i = 0; i < MaxCheckTicks; i++) { self.Iteration(1); foreach (Physic.PCar enemy in enemies) { enemy.Iteration(1); Vector distance = enemy.Pos - self.Pos; double angle = Math.Abs(distance.Normalize().Cross(self.Dir)); double angleSpeed = Math.Abs(self.Dir.Dot(enemy.Dir)); if (i > MinCheckTicks && distance.Length < checkRadius && angle.LessDotWithAngle(maxAngle) && angleSpeed.LessDotWithAngle(maxAngle)) { return(true); } } } return(false); }
public override bool valid() { Physic.PCar self = new Physic.PCar(car, game); List <Physic.PCar> enemies = new List <Physic.PCar>(); foreach (Car iter in world.Cars) { if (iter.Id != car.Id) { enemies.Add(new Physic.PCar(iter, game)); } } return(checkSideHit(self, enemies)); }
public static double AngleForZeroWheelTurn(this Car car, Game game) { Physic.PCar physicCar = new Physic.PCar(car, game); physicCar.setWheelTurn(0); for (int i = 0; i < 25; i++) { physicCar.Iteration(2); if (Math.Abs(physicCar.WheelTurn) <= 1.0e-3) { break; } } return(physicCar.Angle); }