()
| 153 | |
| 154 | |
| 155 | function draw() { |
| 156 | ctx.clearRect(0, 0, canvas.width, canvas.height); |
| 157 | drawBricks(); |
| 158 | drawBall(); |
| 159 | drawPaddle(); |
| 160 | drawScore(); |
| 161 | drawLives(); |
| 162 | collisionDetection(); |
| 163 | mySound=new sound("../assets/sounds/IOS (Notification).mp3"); |
| 164 | urSound=new sound("../assets/sounds/Avengers Notification Tone.mp3"); |
| 165 | overSound=new sound("../assets/sounds/Game Over.mp3"); |
| 166 | // liv=new sound("percussion-sound.mp3"); |
| 167 | |
| 168 | if(x + dx > canvas.width-ballRadius || x + dx < ballRadius) { |
| 169 | dx = -dx; |
| 170 | } |
| 171 | if(y + dy < ballRadius) { |
| 172 | dy = -dy; |
| 173 | } |
| 174 | else if(y + dy > canvas.height-ballRadius) { |
| 175 | if(x > paddleX && x < paddleX + paddleWidth) { |
| 176 | dy = -dy; |
| 177 | } |
| 178 | else { |
| 179 | lives--; |
| 180 | //liv.play(); |
| 181 | if(lives<=0) { |
| 182 | ctx.rect(0, 0, canvas.width,canvas.height); |
| 183 | |
| 184 | ctx.fillStyle = "rgba(0,0,0,1)"; |
| 185 | ctx.fill(); |
| 186 | |
| 187 | ctx.font = "30px Arial"; |
| 188 | ctx.fillStyle = "white"; |
| 189 | ctx.textAlign = "center"; |
| 190 | |
| 191 | ctx.fillText("GAME OVER SCORE IS " +score, canvas.width / 2,canvas.height / 2); |
| 192 | overSound.play(); |
| 193 | clearInterval(animateInterval); |
| 194 | } |
| 195 | else { |
| 196 | x = canvas.width/2; |
| 197 | y = canvas.height-30; |
| 198 | dx = 3; |
| 199 | dy = -3; |
| 200 | paddleX = (canvas.width-paddleWidth)/2; |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | if(rightPressed && paddleX < canvas.width-paddleWidth) { |
| 206 | paddleX += 7; |
| 207 | } |
| 208 | else if(leftPressed && paddleX > 0) { |
| 209 | paddleX -= 7; |
| 210 | } |
| 211 | |
| 212 | x += dx; |
nothing calls this directly
no test coverage detected