Andrei Roman · @urbandrei

Posted 2 years ago
211 followers
70.2K views
1.19K likes
31 comments
66 shares

Code below ————— <!DOCTYPE html> <html> <head> <script> input = [] document.addEventListener('keydown', function(event) { if(!input.includes(event.key)) { input.push(event.key) } }) document.addEventListener('keyup', function(event) { i = input.indexOf(event.key) if(i != -1) { input.splice(i,1) } }) x = 0 setInterval(function() { if (input.includes("a")) { x = x - 10 } else if (input.includes("d")) { x = x + 10 } document.getElementById("player").style.left = x + "px" },1000/60) </script> </head> <body> hello world <div id="player" style="height:100px; width:100px; background-color:black; position: fixed; bottom: 0; left: 0;"></div> </body> </html> #indiegame #coding #programming #howto #gamedev