protected abstract bool DetectCollision(LineBody lineBody);
Exemple #2
0
 /// <summary>
 /// Detect collision with a line body
 /// </summary>
 /// <param name="lineBody"></param>
 /// <returns></returns>
 protected override bool DetectCollision(LineBody lineBody)
 {
     return false;
 }
Exemple #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;
        }