This is a very basic top-down collision engine. It also works if the sprite is a shape other than a perfect square.
Original script by @griffpatch, but I repurposed it and edited it too; it now prioritizes the cardinal axes along with a couple other minor modifications.