private float CalculateDistance(GameObjectState self, GameObjectState objectInFront) { float selfCenterY = self.BoundingBox.CenterY; float otherCenterY = objectInFront.BoundingBox.CenterY; float distanceBetweenCars = Math.Abs(selfCenterY - otherCenterY) - self.BoundingBox.Height / 2 - objectInFront.BoundingBox.Height / 2; return(distanceBetweenCars); }
private bool WouldCrash(GameObjectState self, GameObjectState objectInFront) { float otherDistanceToStop = objectInFront.DistanceToStop; float selfDistancveToStop = self.DistanceToStop; float distanceBetweenCars = self.DistanceFrom(objectInFront); float plusSafeDistance = 5; return(distanceBetweenCars < selfDistancveToStop - otherDistanceToStop + plusSafeDistance && self.VY > 0); }
public float DistanceFrom(GameObjectState other) => CalculateDistance(this, other);
public bool WouldCrashWith(GameObjectState other) => WouldCrash(this, other);