Skip to content

Instantly share code, notes, and snippets.

@philldev
Created December 25, 2022 05:36
Show Gist options
  • Save philldev/b85847acb8d7a7c438629d8b4dc5fa5a to your computer and use it in GitHub Desktop.
Save philldev/b85847acb8d7a7c438629d8b4dc5fa5a to your computer and use it in GitHub Desktop.
check collision between 2 rectangle
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