Created
December 25, 2022 05:36
-
-
Save philldev/b85847acb8d7a7c438629d8b4dc5fa5a to your computer and use it in GitHub Desktop.
check collision between 2 rectangle
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
const collided = (r1: Rectangle, r2: Rectangle) => { | |
return ( | |
r1.position.x + r1.size.width >= r2.position.x && | |
r1.position.y + r1.size.height >= r2.position.y && | |
r1.position.y <= r2.position.y + r2.size.height && | |
r1.position.x <= r2.position.x + r2.size.height | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment