Created
January 13, 2021 01:11
-
-
Save remarkablemark/77ff36487a8bc291de1182d782cfc554 to your computer and use it in GitHub Desktop.
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
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