Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. //Create the ball object
  2. var ball = new Ball();
  3.  
  4. // An object to convert keycodes into action names
  5. var keyActions = {
  6. 32: "stop"
  7. 37: "left"
  8. 38: "up"
  9. 39: "right"
  10. 40: "down"
  11. };
  12.  
  13. // The keydown handler that will be called for every keypress
  14. $("body").keydown(function (event) {
  15. var direction = keyActions[event.keyCode];
  16.  
  17. ball.setDirection(direction);
  18. });
  19.  
  20. // The animation function, called every 30 ms
  21. setInterval(function () {
  22. ctx.clearRect(0, 0, width, height);
  23.  
  24.  
  25. ball.draw();
  26. ball.move();
  27.  
  28. ctx.strokeRect(0, 0, width, height);
  29. }, 30);
  30. </script>
  31. </body>
  32. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement