June 2015
Beginner
354 pages
8h 23m
English
We will use an approach, similar to that of checking the boundary, to check the collision:
js/pingpong.js file that we used in the previous section.moveBall function, we have already reserved the place to put the collision detection code there. Find the line with // check paddles here.// Variables for checking paddles var ballX = ball.x + ball.speed * ball.directionX; var ballY = ball.y + ball.speed * ball.directionY; // check moving paddle here, later. // check left paddle if (ballX >= pingpong.paddleA.x && ballX < pingpong.paddleA.x ...
Read now
Unlock full access