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

Function draw

assets/js/breakout.js:155–215  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153
154
155function draw() {
156ctx.clearRect(0, 0, canvas.width, canvas.height);
157drawBricks();
158drawBall();
159drawPaddle();
160drawScore();
161drawLives();
162collisionDetection();
163mySound=new sound("../assets/sounds/IOS (Notification).mp3");
164urSound=new sound("../assets/sounds/Avengers Notification Tone.mp3");
165overSound=new sound("../assets/sounds/Game Over.mp3");
166// liv=new sound("percussion-sound.mp3");
167
168if(x + dx > canvas.width-ballRadius || x + dx < ballRadius) {
169 dx = -dx;
170}
171if(y + dy < ballRadius) {
172 dy = -dy;
173}
174else 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
205if(rightPressed && paddleX < canvas.width-paddleWidth) {
206 paddleX += 7;
207}
208else if(leftPressed && paddleX > 0) {
209 paddleX -= 7;
210}
211
212x += dx;

Callers

nothing calls this directly

Calls 6

drawBricksFunction · 0.85
drawLivesFunction · 0.85
collisionDetectionFunction · 0.85
drawBallFunction · 0.70
drawPaddleFunction · 0.70
drawScoreFunction · 0.70

Tested by

no test coverage detected