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

Function collisionDetection

assets/js/breakout.js:68–96  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

66}
67}
68function collisionDetection() {
69for(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
98function drawBall() {
99ctx.beginPath();

Callers 1

drawFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected