MDN breakout step 9
plus pausing
This commit is contained in:
parent
e9978041a7
commit
a649c14487
@ -185,10 +185,25 @@ canvas { background: #eee; display: block; margin: 0 auto; }
|
|||||||
else if(e.keyCode == 37) {
|
else if(e.keyCode == 37) {
|
||||||
leftPressed = false;
|
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("keydown", keyDownHandler, false);
|
||||||
document.addEventListener("keyup", keyUpHandler, false);
|
document.addEventListener("keyup", keyUpHandler, false);
|
||||||
|
document.addEventListener("mousemove", mouseMoveHandler, false);
|
||||||
setInterval(draw, 10);
|
setInterval(draw, 10);
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
Reference in New Issue
Block a user