Skip to content

Instantly share code, notes, and snippets.

@johnhoulder
Last active December 28, 2018 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnhoulder/f738e86f70c4d38c66e8d06b31ed11c0 to your computer and use it in GitHub Desktop.
Save johnhoulder/f738e86f70c4d38c66e8d06b31ed11c0 to your computer and use it in GitHub Desktop.
GAME!!!
/**
* GAME!!!
*/
body {
background-color: black;
}
<canvas id="canvas" width="640" height="640"></canvas>
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);
{"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