SunsetHigh.CollisionManager.collisionWithInteractableAtRelative C# (CSharp) Method

collisionWithInteractableAtRelative() public static method

Returns an interactable in the current world's scene that p_interactable collides with if its position were changed. if p_interactable is colliding with p_exclude, that collision doesn't count (i.e. it doesn't make sense to check whether something is colliding with itself)
public static collisionWithInteractableAtRelative ( IInteractable p_interactable, Point p_offset, IInteractable p_exclude ) : IInteractable
p_interactable IInteractable Interactable to check
p_offset Point The proposed movement of the Interactable
p_exclude IInteractable An interactable to exclude from collision checking
return IInteractable
        public static IInteractable collisionWithInteractableAtRelative(IInteractable p_interactable, Point p_offset, IInteractable p_exclude)
        {
            IInteractable l_collidedObject = null;
            foreach (IInteractable i in WorldManager.m_currentRoom.Interactables)
            {
                if (i == p_exclude || m_excluded.Contains(i))
                {
                    continue;
                }
                Rectangle l_copy = p_interactable.getBoundingRect();    //preserve this just in case
                Rectangle l_spriteBounds;
                l_spriteBounds.X = l_copy.X + p_offset.X;
                l_spriteBounds.Y = l_copy.Y + p_offset.Y;
                l_spriteBounds.Width = l_copy.Width;
                l_spriteBounds.Height = l_copy.Height;

                Rectangle l_charBounds = i.getBoundingRect();
                if (l_spriteBounds.Intersects(l_charBounds))
                {
                    l_collidedObject = i;
                    break;
                }
            }
            return l_collidedObject;
        }