xxxxxxxxxx
190
let images = [];
let counter = 0;
let positionx;
// Brain Images
let brain;
let brain1;
let brain2;
// First idle animation
let num = 3;
// Second stand animation
let sum = 3;
// Third walk animation
let tun = 8;
// Position for brain
let a = 400;
let b = 200;
// Position for brain1
let c = 220;
let d = 200;
// Position for brain2
let e = 242;
let f = 200;
// Position for zombie
let x = -10;
let y = 140;
// Move brain left
let brainMoveRight = true;
// Draw brain
let brainAppear = true;
// Draw brain1
let brainAppear1 = false;
// Draw brain2
let brainAppear2 = false;
// Let move right
let moveRight = false;
let city;
function preload ()
{
// Idle animation
while (num > 0)
{
for (let i = 1; i <= 15; i++)
{
let img = loadImage("Idle" + i + ".PNG");
images.push(img);
}
num = num - 1;
console.log(num);
}
// Stand animation
while (sum > 0)
{
for (let i = 1; i <= 14; i ++)
{
let img3 = loadImage("stand" + i + ".PNG");
images.push(img3);
}
sum = sum - 1;
console.log(sum);
}
// Walking animation
while (tun > 0)
{
for (let i = 1; i <= 10; i ++)
{
let img2 = loadImage("walk" + i + ".PNG");
images.push(img2);
}
moveRight = true;
tun = tun - 1;
console.log(tun);
}
// Brain and city image
brain = loadImage("brain1.PNG");
brain1 = loadImage("brain2.PNG");
brain2 = loadImage("brain3.PNG");
city = loadImage("city.jpg");
console.log(images[0]);
}
function setup() {
createCanvas(400, 400);
noStroke();
frameRate(10);
}
function draw() {
background(220);
// City Image
drawCity();
// Pink Zombie Image
let img = images[counter];
image(img, x, y, 250, 250);
counter++;
if (counter == images.length) {
counter = 0;
}
// Zombie Speed
if (moveRight == true)
{
x = x + 1.5;
}
// Brain image
if (brainAppear)
{
image(brain, a, b, 200, 200);
}
if (brainAppear2 == true)
{
image(brain2, e, f, 200, 200);
e = e + 2;
}
if (c == 242)
{
brainAppear1 = false;
brainAppear2 = true;
}
if (brainAppear1 == true)
{
image(brain1, c, d, 200, 200);
c = c + 0.5;
}
// Move Brain
if (brainMoveRight)
{
a = a - 4;
}
if (a == 220)
{
brainMoveRight = false;
brainAppear = false;
brainAppear1 = true;
}
// Tint Feauture
function drawCity()
{
image(city, 0, 0, 400, 400);
if (keyIsPressed == true)
{
tint(0, 153, 204, 126);
}
}
}