ZAMBIE GAM
by Kyle Bezio
HTML
<canvas id="myCanvas" width="800" height="550" style="border:1px solid #000000;"></canvas>
JavaScript
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
var tileSize = 16;
var key = 0;
var map = [
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],
[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
];
function drawMap() {
context.fillStyle = "white";
context.fillRect(0, 0, canvas.width, canvas.height);
for (i=0; i < map.length; i++) {
for (j=0; j < map[i].length; j++) {
if (map[i][j] === 1) {
context.fillStyle = "black";
context.fillRect(j * tileSize, i * tileSize, tileSize, tileSize);
}
}
}
}
function drawPlayer() {
context.fillStyle = "red";
context.save();
context.translate(player.x + 1/2 * player.size, player.y + 1/2 * player.size);
context.rotate(player.rot);
context.fillRect(-1/2 * player.size, -1/2 * player.size, player.size, player.size);
context.fillStyle = "black";
context.fillRect(1/4 * player.size, -1/4 * player.size, 1/8 * player.size, 1/8 * player.size)
context.fillRect(1/4 * player.size, 1/8 * player.size, 1/8 * player.size, 1/8 * player.size)
context.restore();
}
function drawObject() {
context.fillStyle = "limeGreen";
context.save();
context.translate(object.x + 1/2 * object.size, object.y + 1/2 * object.size);
context.rotate(player.rot);
context.fillRect(-1/2 * object.size, -1/2 * object.size, player.size, player.size);
context.restore();
}
function gameCycle() {
drawMap();
moveObject(object);
move();
drawObject();
drawPlayer();
context.fillStyle = "black";
context.font = "40px Arial";
context.fillText("Key: " + key, 300, 40);
context.fillText("Speed: " +...