Created
February 24, 2019 22:12
-
-
Save bashbaugh/ccfddf2989b06cf2ae3abd6d2ad23256 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>JavaScript Game</title> | |
| </head> | |
| <body onload="init()"> | |
| <h1>JavaScript Game</h1> | |
| <p>Here is a simple JavaScript game:</p> | |
| <canvas id="c" width="400" height="400"></canvas> | |
| <script> | |
| console.log("Starting the script!"); | |
| let canvas_element = document.getElementById("c"); | |
| let canvas = canvas_element.getContext("2d"); | |
| document.onkeydown = key_pressed; | |
| function init() | |
| { | |
| draw_background(); | |
| canvas.fillStyle = "#FFFFFF"; | |
| canvas.font = "25px Arial"; | |
| canvas.fillText("Press the up arrow to start", 40, 200); | |
| } | |
| function draw_background() | |
| { | |
| canvas.clearRect(0, 0, canvas_element.width, canvas_element.height); | |
| canvas.fillStyle = "#1EBA00"; | |
| canvas.fillRect(0, 0, canvas_element.width, canvas_element.height); | |
| } | |
| function key_pressed(key) | |
| { | |
| if (key.key == "ArrowUp") | |
| { | |
| console.log("up"); | |
| } | |
| if (key.key == "ArrowLeft") | |
| { | |
| console.log("left"); | |
| } | |
| if (key.key == "ArrowRight") | |
| { | |
| console.log("right"); | |
| } | |
| } | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment