Created
July 14, 2010 22:00
-
-
Save Luiji/476161 to your computer and use it in GitHub Desktop.
box collision algorithm in lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This script was written by Luiji Maryo, http://github.com/Luiji . | |
-- It has been released under the Public Domain. | |
-- Collision detection function. | |
-- Checks if box1 and box2 overlap. | |
-- w and h mean width and height. | |
function CheckCollision(box1x, box1y, box1w, box1h, box2x, box2y, box2w, box2h) | |
if box1x > box2x + box2w - 1 or -- Is box1 on the right side of box2? | |
box1y > box2y + box2h - 1 or -- Is box1 under box2? | |
box2x > box1x + box1w - 1 or -- Is box2 on the right side of box1? | |
box2y > box1y + box1h - 1 -- Is b2 under b1? | |
then | |
return false -- No collision. Yay! | |
else | |
return true -- Yes collision. Ouch! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment