Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 0.62 KB | None | 0 0
  1. <html>
  2.   <head>
  3.     <title>Pong!</title>
  4.     <script>
  5.  
  6. var run = function() {
  7.   var canvas = document.getElementById("game");
  8.   var ctx = canvas.getContext("2d");
  9.   ctx.fillStyle = "red";
  10.   ctx.fillRect(0, 0, 150, 75);
  11.  
  12.   ctx.fillStyle = "black";
  13.   ctx.fillText("Mr. K was here", 10, 20);
  14.  
  15. };
  16.  
  17. var keypress = function(e) {
  18.     if (e.keyCode == 38 || e.keyCode == 40) {
  19.         alert(e.keyCode);
  20.     }
  21. };
  22.  
  23. setInterval(run, 20);
  24.  
  25. window.addEventListener("keydown",keypress,false);
  26.  
  27.     </script>
  28.   </head>
  29.   <body onload="run()">
  30.  
  31.     <canvas id=game width=600 height=400></canvas>
  32.  
  33.   </body>
  34. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement