| 157 | |
| 158 | // collision Detect function |
| 159 | function 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 |
| 175 | function update() { |