Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Create the ball object
- var ball = new Ball();
- // An object to convert keycodes into action names
- var keyActions = {
- 32: "stop"
- 37: "left"
- 38: "up"
- 39: "right"
- 40: "down"
- };
- // The keydown handler that will be called for every keypress
- $("body").keydown(function (event) {
- var direction = keyActions[event.keyCode];
- ball.setDirection(direction);
- });
- // The animation function, called every 30 ms
- setInterval(function () {
- ctx.clearRect(0, 0, width, height);
- ball.draw();
- ball.move();
- ctx.strokeRect(0, 0, width, height);
- }, 30);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement