Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 public float DistanceFrom(GameObjectState other) => CalculateDistance(this, other);
Beispiel #4
0
 public bool WouldCrashWith(GameObjectState other) => WouldCrash(this, other);