Skip to content

Instantly share code, notes, and snippets.

@remarkablemark
Created January 13, 2021 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save remarkablemark/77ff36487a8bc291de1182d782cfc554 to your computer and use it in GitHub Desktop.
Save remarkablemark/77ff36487a8bc291de1182d782cfc554 to your computer and use it in GitHub Desktop.
function checkBoundaryCollision(image) {
var hasCollision = false;
// left or right collision
if (position.x < 0 || position.x + image.width > width) {
velocity.x *= -1;
hasCollision = true;
}
// top or bottom collision
if (position.y < 0 || position.y + image.height > height) {
velocity.y *= -1;
hasCollision = true;
}
return hasCollision;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment