| 66 | } |
| 67 | } |
| 68 | function collisionDetection() { |
| 69 | for(var c=0; c<brickColumnCount; c++) { |
| 70 | for(var r=0; r<brickRowCount; r++) { |
| 71 | var b = bricks[c][r]; |
| 72 | if(b.status == 1) { |
| 73 | if(x > b.x && x < b.x+brickWidth && y > b.y && y < b.y+brickHeight) { |
| 74 | dy = -dy; |
| 75 | b.status = 0; |
| 76 | mySound.play(); |
| 77 | score++; |
| 78 | if(score == brickRowCount*brickColumnCount) { |
| 79 | |
| 80 | ctx.rect(0, 0, canvas.width,canvas.height); |
| 81 | ctx.fillStyle = "rgba(0,0,0,1)"; |
| 82 | ctx.fill(); |
| 83 | |
| 84 | ctx.font = "20px Arial"; |
| 85 | ctx.fillStyle = "white"; |
| 86 | ctx.textAlign = "center"; |
| 87 | ctx.fillText("CONGRATS YOU WIN! YOUR SCORE IS " +score, canvas.width / 2,canvas.height / 2); |
| 88 | urSound.play(); |
| 89 | clearInterval(animateInterval); |
| 90 | |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | function drawBall() { |
| 99 | ctx.beginPath(); |