Exemplo n.º 1
0
        public void FRect_Intersects()
        {
            FRect A = new FRect(0, 0, 5, 5);
            FRect B = new FRect(3, 3, 5, 5);
            FRect C = new FRect(1, 1, 1, 1);
            FRect D = new FRect(5, 5, 5, 5);
            FRect E = new FRect(6, 5, 5, 5);
            FRect F = new FRect(5, 6, 5, 5);
            FRect G = new FRect(-1, -1, 7, 7);

            Debug.Assert(A.Intersects(A), "1");
            Debug.Assert(A.Intersects(B), "2");
            Debug.Assert(A.Intersects(C), "3");
            Debug.Assert(!A.Intersects(D), "4");
            Debug.Assert(!A.Intersects(E), "5");
            Debug.Assert(!A.Intersects(F), "6");
            Debug.Assert(A.Intersects(G), "7");

            Debug.Assert(A.IntersectsOrTouches(A), "a");
            Debug.Assert(A.IntersectsOrTouches(B), "b");
            Debug.Assert(A.IntersectsOrTouches(C), "c");
            Debug.Assert(A.IntersectsOrTouches(D), "d");
            Debug.Assert(!A.IntersectsOrTouches(E), "e");
            Debug.Assert(!A.IntersectsOrTouches(F), "f");
            Debug.Assert(A.IntersectsOrTouches(G), "g");
        }
Exemplo n.º 2
0
 /// <summary>
 /// Determines collision with the Wall AABB and if that yields true it will check the supplied FRect against it's wall segments. If any of those also collides then that one will take damage.
 /// </summary>
 /// <param name="collisionRect">The AABB of the collider</param>
 /// <returns>true if any segment collides with the supplied AABB</returns>
 public bool Collides(FRect collisionRect)
 {
     if (WallBoundary.Intersects(collisionRect))
     {
         foreach (WallSegment segment in Segments)
         {
             if (segment.CollisionRect.Intersects(collisionRect) && segment.HP > 0)
             {
                 segment.HP--;
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a list of items intersecting a specified rectangle
        /// </summary>
        /// <param name="Rect">The rectangle</param>
        /// <param name="ItemsFound">The list to add found items to (list will not be cleared first)</param>
        /// <remarks>ItemsFound is assumed to be initialized, and will not be cleared</remarks>
        public void GetItems(FRect Rect, ref List <QuadTreePositionItem <T> > ItemsFound)
        {
            // test the point against this node
            if (Rect.Intersects(Rect))
            {
                // test the point in each item
                foreach (QuadTreePositionItem <T> Item in Items)
                {
                    if (Item.Rect.Intersects(Rect))
                    {
                        ItemsFound.Add(Item);
                    }
                }

                // query all subtrees
                if (IsPartitioned)
                {
                    TopLeftNode.GetItems(Rect, ref ItemsFound);
                    TopRightNode.GetItems(Rect, ref ItemsFound);
                    BottomLeftNode.GetItems(Rect, ref ItemsFound);
                    BottomRightNode.GetItems(Rect, ref ItemsFound);
                }
            }
        }