shivajikobardan
Legendary Coder
Code:
function checkBoundaryCollision() {
if (x - ballRadius <= 0 || x + ballRadius >= canvasWidth) {
dx = -dx;
}
if (y - ballRadius <= 0 || y + ballRadius >= canvasHeight) {
dy = -dy;
}
}
Full code here: https://codepen.io/pelko/pen/gOjXdaq

