Example #1
0
 protected abstract bool DetectCollision(LineBody lineBody);
Example #2
0
 /// <summary>
 /// Detect collision with a line body
 /// </summary>
 /// <param name="lineBody"></param>
 /// <returns></returns>
 protected override bool DetectCollision(LineBody lineBody)
 {
     return false;
 }
Example #3
0
        /// <summary>
        /// Detect a collision with a line body
        /// </summary>
        /// <param name="lineBody"></param>
        /// <returns></returns>
        protected override bool DetectCollision(LineBody lineBody)
        {
            Vector2 closestPointOnLineBody = lineBody.GetClosestPointOnPerimeter(this.Position);

            bool touchingLine = ((closestPointOnLineBody - this.Position).LengthSquared() < this.Radius * this.Radius);
            bool willCrossLine = !(this.Position - closestPointOnLineBody).HasSameDirection(this.Position - this.Velocity - lineBody.GetClosestPointOnPerimeter(this.Position - this.Velocity));
            bool result = touchingLine || willCrossLine;

            return result;
        }