Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title><a href="https://www.brsoftech.com/au/game-development.html">Mobile Game Development</title></a>
- <style>
- #game {
- height: 200px;
- width: 200px;
- background-color: #000000;
- position: relative;
- }
- #player {
- height: 20px;
- width: 20px;
- background-color: #ff0000;
- position: absolute;
- bottom: 0;
- left: 90px;
- }
- </style>
- </head>
- <body>
- <div id="game">
- <div id="player"></div>
- </div>
- <script>
- var player = document.getElementById("player");
- document.addEventListener("keydown", function(event) {
- if(event.key === "ArrowLeft") {
- player.style.left = (parseInt(player.style.left) - 10) + "px";
- }
- else if(event.key === "ArrowRight") {
- player.style.left = (parseInt(player.style.left) + 10) + "px";
- }
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement