Advertisement
brmanu

Game Provider BR Softech

Apr 18th, 2023
1,672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title><a href="https://www.brsoftech.com/au/game-development.html">Mobile Game Development</title></a>
  5.     <style>
  6.         #game {
  7.             height: 200px;
  8.             width: 200px;
  9.             background-color: #000000;
  10.             position: relative;
  11.         }
  12.        
  13.         #player {
  14.             height: 20px;
  15.             width: 20px;
  16.             background-color: #ff0000;
  17.             position: absolute;
  18.             bottom: 0;
  19.             left: 90px;
  20.         }
  21.     </style>
  22. </head>
  23. <body>
  24.     <div id="game">
  25.         <div id="player"></div>
  26.     </div>
  27.  
  28.     <script>
  29.         var player = document.getElementById("player");
  30.  
  31.         document.addEventListener("keydown", function(event) {
  32.             if(event.key === "ArrowLeft") {
  33.                 player.style.left = (parseInt(player.style.left) - 10) + "px";
  34.             }
  35.             else if(event.key === "ArrowRight") {
  36.                 player.style.left = (parseInt(player.style.left) + 10) + "px";
  37.             }
  38.         });
  39.     </script>
  40. </body>
  41. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement