Last active
December 28, 2018 18:06
-
-
Save johnhoulder/f738e86f70c4d38c66e8d06b31ed11c0 to your computer and use it in GitHub Desktop.
GAME!!!
This file contains 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
/** | |
* GAME!!! | |
*/ | |
body { | |
background-color: black; | |
} |
This file contains 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
<canvas id="canvas" width="640" height="640"></canvas> |
This file contains 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
const canvas = document.getElementById('canvas'); | |
const ctx = canvas.getContext('2d'); | |
const grid = [ | |
[0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0], | |
[0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0], | |
[0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0], | |
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0], | |
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0], | |
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0] | |
]; | |
const playerStart = [3, 1]; | |
let startTime = 0; | |
ctx.fillStyle = 'white'; | |
ctx.fillRect(0, 0, canvas.width, canvas.height); | |
function drawMap() { | |
ctx.clearRect(0, 0, canvas.width, canvas.height); | |
for (let y = 0; y < grid.length; y++) { | |
for (let x = 0; x < grid[y].length; x++) { | |
switch(grid[y][x]) { | |
case 0: | |
ctx.fillStyle = 'black'; | |
ctx.fillRect(x * 32, y * 32, 32, 32); | |
break; | |
case 1: | |
ctx.fillStyle = '#414141'; | |
ctx.fillRect(x * 32, y * 32, 32, 32); | |
break; | |
} | |
} | |
} | |
} | |
function iterate(timestamp) { | |
if(startTime === 0) { | |
startTime = timestamp; | |
} | |
window.requestAnimationFrame(iterate); | |
} | |
window.requestAnimationFrame(iterate); |
This file contains 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
{"view":"split","fontsize":"100","seethrough":"","prefixfree":"1","page":"javascript"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment