Exemple #1
0
        /// <summary>
        /// Determines if there is a collision between a circle and rectangle
        /// </summary>
        /// <param name="r">The bounding rectangle</param>
        /// <param name="c">The bounding circle</param>
        /// <returns>true for collision, false otherwise</returns>
        public static bool Collides(BoundingRectangle r, BoundingCircle c)
        {
            float nX = MathHelper.Clamp(c.Center.X, r.Left, r.Right);
            float nY = MathHelper.Clamp(c.Center.Y, r.Top, r.Bottom);

            return(Math.Pow(c.Radius, 2) >= Math.Pow(c.Center.X - nX, 2) + Math.Pow(c.Center.Y - nY, 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 a collision between two BoundingCircles
 /// </summary>
 /// <param name="a"> The first bounding circle </param>
 /// <param name="b"> The second bounding circle </param>
 /// <returns> true for collision, false otherwise </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));
 }