Beispiel #1
0
        public bool CollidesWith(AARect2 rect)
        {
            AARect2 rect1 = this;
            AARect2 rect2 = rect;

            return(rect1.TopLeft.X < rect2.TopLeft.X + rect2.Width &&
                   rect1.TopLeft.X + rect1.Width > rect2.TopLeft.X &&
                   rect1.TopLeft.Y < rect2.TopLeft.Y + rect2.Height &&
                   rect1.TopLeft.Y + rect1.Height > rect2.TopLeft.Y);
        }
Beispiel #2
0
        /// <summary>
        /// Get all the entities in an enumerable that are colliding with a rect.
        /// </summary>
        public static HashSet <Entity> HitTest(IEnumerable <Entity> entities, AARect2 rect)
        {
            HashSet <Entity> results = new HashSet <Entity>();

            foreach (var entity in entities)
            {
                if (entity.BoundingBox.CollidesWith(rect))
                {
                    results.Add(entity);
                }
            }
            return(results);
        }