Exemple #1
0
        /// <summary>
        /// Detects a collision between a rectangle and a circle
        /// </summary>
        /// <param name="c"></param>
        /// <param name="r"></param>
        /// <returns></returns>
        public static bool Collides(BoundingCircle c, BoundingRectangle r)
        {
            float NearestX = MathHelper.Clamp(c.Center.X, r.Left, r.Right);
            float NearestY = MathHelper.Clamp(c.Center.Y, r.Top, r.Bottom);

            return(Math.Pow(c.Radius, 2) >=
                   Math.Pow(c.Center.X - NearestX, 2) +
                   Math.Pow(c.Center.Y - NearestY, 2));
        }
 /// <summary>
 /// Test for a collision between this and another BoundingCircle
 /// </summary>
 /// <param name="other">The other bounding Circle</param>
 /// <returns>true for a collision</returns>
 public bool CollidesWith(BoundingCircle other)
 {
     return(CollisionHelper.Collides(this, other));
 }
Exemple #3
0
 public static bool Collides(BoundingRectangle r, BoundingCircle c) => Collides(c, r);
Exemple #4
0
 /// <summary>
 /// Detects collision between two BoundingCircles
 /// </summary>
 /// <param name="a">The first BoudningCircle</param>
 /// <param name="b">The second BoudningCircle</param>
 /// <returns></returns>
 public static bool Collides(BoundingCircle a, BoundingCircle b)
 {
     return(Math.Pow(a.Radius + b.Radius, 2) >=
            Math.Pow(a.Center.X - b.Center.X, 2) +
            Math.Pow(a.Center.Y - b.Center.Y, 2));
 }