<script src="http://spelprogrammering.nu/simple.js">
function start()
{
zombies = [];
deadZombies = [];
clock = 0;
spawn = 30;
bulletsFired = 0;
zombiesKilled = 0;
hideMouse();
circle(10, 10, 10, "lightgreen");
zombieColor = getPixel(10, 10);
fill("black");
}
function update()
{
fill("black");
rectangle(0, 0, totalWidth, totalHeight, "37B6FF");
rectangle(0, totalHeight / 2, totalWidth, totalHeight-300, "green");
save();
translate(totalWidth / 2 - 370, totalHeight / 2 - 300);
rectangle(200, 150, 300, 200, "A22416");
circle(510, 100, 40, "white");
circle(550, 100, 50, "white");
circle(600, 100, 30, "white");
circle(640, 120, 30, "white");
circle(620, 90, 30, "white");
circle(150, 100, 40, "white");
circle(200, 100, 40, "white");
circle(100, 100, 30, "white");
circle(250, 90, 30, "white");
triangle(200, 150, 350, 30, 500, 150, "A22416");
triangle(200, 150, 350, 30, 500, 150, "black");
triangle(210, 150, 350, 40, 490, 150, "A22416");
triangle(210, 150, 350, 40, 490, 150, "white");
triangle(215, 150, 350, 45, 485, 150, "A22416");
rectangle(200, 150, 10, 200, "white");
rectangle(490, 150, 10, 200, "white");
rectangle(250, 180, 50, 50, "C2E9FF");
rectangle(400, 180, 50, 50, "C2E9FF");
rectangle(325, 270, 50, 80, "996633");
rectangle(325, 270, 2, 80, "845E3A");
rectangle(330, 270, 2, 80, "845E3A");
rectangle(335, 270, 2, 80, "845E3A");
rectangle(340, 270, 2, 80, "845E3A");
rectangle(345, 270, 2, 80, "845E3A");
rectangle(350, 270, 2, 80, "845E3A");
rectangle(355, 270, 2, 80, "845E3A");
rectangle(360, 270, 2, 80, "845E3A");
rectangle(365, 270, 2, 80, "845E3A");
rectangle(370, 270, 2, 80, "845E3A");
rectangle(375, 270, 2, 80, "845E3A");
rectangle(423, 180, 3, 50, "black");
rectangle(400, 200, 50, 3, "black");
rectangle(274, 180, 3, 50, "black");
rectangle(250, 200, 50, 3, "black");
circle(335, 300, 3, "black");
rectangle(335, 299, 8, 2, "black");
circle(335, 300, 3, "black");
rectangle(600, 200, 40, 150, "280000");
circle(600, 200, 40, "339900");
circle(640, 200, 40, "339900");
circle(620, 150, 40, "339900");
circle(670, 200, 30, "339900");
circle(570, 200, 40, "339900");
circle(590, 160, 40, "339900");
circle(650, 160, 40, "339900");
circle(600, 200, 7, "red");
circle(640, 190, 8, "red");
circle(600, 150, 9, "red");
circle(680, 200, 7, "red");
circle(550, 200, 10, "red");
circle(650, 140, 7, "red");
restore();
rectangle(totalWidth / 2 + 32, totalHeight / 2 - 78, 13, 10, "#996600");
rectangle(totalWidth / 2 + 37, totalHeight / 2 - 83, 2, 7, "black");
circle(totalWidth / 2 + 38, totalHeight / 2 - 72, 3, "black");
for (var i = 0; i < deadZombies.length; i++)
{
var zombie = deadZombies[i];
zombie.update();
}
for (var i = 0; i < zombies.length; i++)
{
var zombie = zombies[i];
if (! zombie.dead)
{
zombie.update();
pixel = getPixel(mouse.x, mouse.y);
if (mouse.left &&
pixel.red == zombieColor.red &&
pixel.green == zombieColor.green &&
pixel.blue == zombieColor.blue)
{
circle(mouse.x, mouse.y, 10, "red");
zombie.dead = true;
zombie.x += 50 + random(50);
zombie.deadAngle = random(360);
zombiesKilled++;
deadZombies.push(zombie);
}
if (zombie.x < 50)
{
blast(totalWidth / 2, totalHeight / 2, 100, 50, "yellow");
blast(totalWidth / 2, totalHeight / 2, 80, 30, "orange");
text(totalWidth / 2 - 200, totalHeight * 0.8, 30,
"BASE SELF DESTRUCT", "black");
stopUpdate();
}
}
}
if (mouse.x > 0 && mouse.left && random(2) == 0)
{
circle(totalWidth / 2 + 38, totalHeight / 2 - 72, 4, "yellow");
line(totalWidth / 2 + 38, totalHeight / 2 - 70,
mouse.x, mouse.y, 2, "yellow");
}
ring(mouse.x, mouse.y, 30, 3, "black");
line(mouse.x - 30, mouse.y, mouse.x - 5, mouse.y, 1, "black");
line(mouse.x + 30, mouse.y, mouse.x + 5, mouse.y, 1, "black");
line(mouse.x, mouse.y - 30, mouse.x, mouse.y - 5, 1, "black");
line(mouse.x, mouse.y + 30, mouse.x, mouse.y + 5, 1, "black");
if (mouse.left)
{
blast(mouse.x, mouse.y, 20, 10, "yellow");
bulletsFired++;
}
if (clock > spawn)
{
clock = 0;
if (clock % spawn == 0) { spawn-- };
zombies.push(new Zombie());
}
clock++;
text(10, 20, 15, "Bullets fired: "+ bulletsFired, "white");
text(10, 45, 15, "Zombies killed: "+ zombiesKilled, "white");
text(10, 70, 15, "Score: "+ (zombiesKilled * 10 - bulletsFired), "white");
}
function blast(x, y, radius, fragments, color)
{
save();
translate(x, y);
circle(0, 0, radius/10, color);
for (var i = 0; i < fragments; i++)
{
rotate(random(360));
circle(random(radius), 0, random(radius/5), color);
}
restore();
}
function Zombie(x, speed, angle)
{
this.x = distance(0, 0, totalWidth / 2, totalHeight / 2) + 100;
this.y = 0;
this.speed = 1 + random(5);
this.angle = 15 + random(150);
this.dead = false;
this.update = function()
{
save();
translate(totalWidth / 2, totalHeight / 2);
rotate(this.angle);
translate(this.x, this.y);
if (this.dead)
{
this.skinColor = "orange";
rotate(this.deadAngle);
}
else
{
this.x -= this.speed;
this.skinColor = "lightgreen";
if (this.angle > 90 && this.angle < 270) { scale(1, -1) };
}
scale(0.5, 0.5);
if (this.dead)
{
save();
for (var i = 0; i < 10; i++)
{
rotate(this.deadAngle % (i * 20));
circle(3 * i, 0, 3 * i, "red");
}
restore();
}
rectangle(3, 30, 23, 65, this.skinColor);
rectangle(3, 15, 23, 65, "gray");
circle(15, 0, 20, this.skinColor);
circle(0, 0, 3, "red");
rectangle(-35, 20, 30, 14, this.skinColor);
rectangle(-20, 20, 30, 14, "gray");
restore();
};
}
</script>