Beispiel #1
0
        /// <summary>
        /// Detect a collision with a circle body
        /// </summary>
        /// <param name="circleBody"></param>
        /// <returns></returns>
        protected override bool DetectCollision(CircleBody circleBody)
        {
            // Get sum of radii
            float radiusSum = this.Radius + circleBody.Radius;

            // Get distance between the two bodies
            Vector2 delta = this.Position - circleBody.Position;

            // Return true if the distance between the center of the two bodies
            // is less than or equal to the sum of the radii
            bool result = (radiusSum * radiusSum) >= (delta.X * delta.X + delta.Y * delta.Y);

            return result;
        }
Beispiel #2
0
        /// <summary>
        /// Construct
        /// </summary>
        /// <param name="body"></param>
        /// <returns></returns>
        private static List<Node> Construct(CircleBody body, int distanceFromBody, int maxDistanceBetweenEachNode)
        {
            List<Node> result = new List<Node>();

            int numNodes = (int)(2 * MathHelper.Pi * body.GetRadius()) / maxDistanceBetweenEachNode;

            for (int i = 0; i < numNodes; i++)
            {
                float angle = ((float)i / (float)numNodes) * MathHelper.TwoPi;
                Vector2 angleUnitVector = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
                result.Add(new Node(body.GetPosition() + (body.GetRadius() + distanceFromBody) * angleUnitVector));
            }

            return result;
        }
Beispiel #3
0
 /// <summary>
 /// Detect collision with a circle body
 /// </summary>
 /// <param name="circleBody"></param>
 /// <returns></returns>
 protected override bool DetectCollision(CircleBody circleBody)
 {
     return circleBody.DetectCollision(this);
 }
Beispiel #4
0
 protected abstract bool DetectCollision(CircleBody circleBody);