Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 93 additions & 1 deletion index.html
32 changes: 31 additions & 1 deletion src/breakout.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
var brickOffsetLeft = 30;
var score = 0;
var totalBricks = 0;

var paused = true;
var bricks = [];
for(var c=0; c<brickColumnCount; c++) {
bricks[c] = [];
Expand All @@ -49,9 +49,28 @@
}
}



document.addEventListener("keydown", keyDownHandler, false);
document.addEventListener("keyup", keyUpHandler, false);

/**Listener for Pause Key, here 'P' is used**/
window.addEventListener('keydown', function (e) {
var key = e.keyCode;
if (key === 80) {
togglePause();
}
});

/**Pause Function**/
function togglePause(){
if (!paused) {
paused = true;
}
else if (paused) {
paused= false;
}
}
function keyDownHandler(e) {
if(e.key == "Right" || e.key == "ArrowRight") {
rightPressed = true;
Expand Down Expand Up @@ -126,6 +145,7 @@
ctx.fillText("Score: "+score, 8, 20);
}


function draw() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawBricks();
Expand All @@ -134,6 +154,15 @@
drawScore();
collisionDetection();

ctx.font = "19px Arial Bold"; /**Pause Instruction**/
ctx.fillStyle = "#2B2B52";
ctx.fillText(" \"P\" to Pause", 350, 20);


if(!paused){
update();
}

if(x + dx > canvas.width-ballRadius || x + dx < ballRadius) {
dx = -dx;
}
Expand Down Expand Up @@ -162,6 +191,7 @@
y += dy;
}


var interval = setInterval(draw, 10);

</script>
Expand Down