Exemple #1
0
        public bool IsColliding(ICollidable secondShape)
        {
            if (secondShape is Convex)
            {
                Convex other = (secondShape as Convex);

                for (int i = 0; i < other.points.Length; i++)
                {
                    if (IsColliding(other.points[i] + other.Position))
                    {
                        return(true);
                    }
                }

                for (int i = 0; i < points.Length; i++)
                {
                    if (other.IsColliding(points[i] + Position))
                    {
                        return(true);
                    }
                }

                return(false);
            }
            else if (secondShape is AABox)
            {
                AABox other = (AABox)secondShape;

                for (int i = 0; i < points.Length; i++)
                {
                    if (other.IsColliding(points[i]))
                    {
                        return(true);
                    }
                }

                Vector2[] corners = new Vector2[] { new Vector2(other.edges.Left, other.edges.Top), new Vector2(other.edges.Right, other.edges.Top),
                                                    new Vector2(other.edges.Right, other.edges.Bottom), new Vector2(other.edges.Left, other.edges.Bottom) };
                for (int i = 0; i < 4; i++)
                {
                    if (IsColliding(corners[i]))
                    {
                        return(true);
                    }
                }

                return(false);
            }

            throw new NotImplementedException("The collision calculation " + secondShape.GetType().Name + " - Convex has not been implemented.");
        }
Exemple #2
0
 /// <summary>
 /// Creates a deep copy of the AABox.
 /// </summary>
 /// <param name="original">The AABox to make a copy of.</param>
 public AABox(AABox original)
 {
     edges = original.edges;
 }