From a649c144871e7f31efcb04e1d226789babd04446 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 3 Jan 2017 16:32:05 -0500 Subject: [PATCH] MDN breakout step 9 plus pausing --- mdn-breakout/index.html | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/mdn-breakout/index.html b/mdn-breakout/index.html index 57491bf..5a6481b 100644 --- a/mdn-breakout/index.html +++ b/mdn-breakout/index.html @@ -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); })();