MCPcopy Create free account
hub / github.com/Vishal-raj-1/Awesome-JavaScript-Projects / collisionDetect

Function collisionDetect

assets/js/pingpong.js:159–172  ·  view source on GitHub ↗
(player, ball)

Source from the content-addressed store, hash-verified

157
158// collision Detect function
159function collisionDetect(player, ball) {
160 // returns true or false
161 player.top = player.y;
162 player.right = player.x + player.width;
163 player.bottom = player.y + player.height;
164 player.left = player.x;
165
166 ball.top = ball.y - ball.radius;
167 ball.right = ball.x + ball.radius;
168 ball.bottom = ball.y + ball.radius;
169 ball.left = ball.x - ball.radius;
170
171 return ball.left < player.right && ball.top < player.bottom && ball.right > player.left && ball.bottom > player.top;
172}
173
174// update function, to update things position
175function update() {

Callers 1

updateFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected