MDN breakout step 9

plus pausing
This commit is contained in:
Dan Buch 2017-01-03 16:32:05 -05:00
parent e9978041a7
commit a649c14487
No known key found for this signature in database
GPG Key ID: FAEF12936DD3E3EC

View File

@ -185,10 +185,25 @@ canvas { background: #eee; display: block; margin: 0 auto; }
else if(e.keyCode == 37) {
leftPressed = false;
}
else if(e.keyCode == 27) {
if(isPaused) {
isPaused = false;
} else {
pauseWithMessage("PAUSE (ESC)");
}
}
}
function mouseMoveHandler(e) {
var relativeX = e.clientX - canvas.offsetLeft;
if(relativeX > (0-paddleWidth) && relativeX < (canvas.width+paddleWidth)) {
paddleX = relativeX - paddleWidth/2;
}
}
document.addEventListener("keydown", keyDownHandler, false);
document.addEventListener("keyup", keyUpHandler, false);
document.addEventListener("mousemove", mouseMoveHandler, false);
setInterval(draw, 10);
})();
</script>