I'm currently trying to make a game themed around zombies, so I made a function that is supposed to draw an ellipse on the canvas that represents the zombie. I am unable to figure out how to get the code that was run by the function to remain on the canvas after the background refreshes. Does anybody have an answer to this problem?
var playerI = {
x: width + 500,
y: height + 300
};
void setup(){
size(1350, 755);
}
//function to spawn zombies
void spawnZombie(let x, let y) {
fill(0, 100, 0);
ellipse(x, y, 50, 50);
}
void draw(){
background(0, 120, 0);
frameRate(60);
//player
fill(250, 220, 0);
ellipse(playerI.x, playerI.y, 50, 50);
//player movement
if (keyPressed && key == 'w') {
playerI.y -= 1.5;
}
if (keyPressed && key == 's') {
playerI.y += 1.5;
}
if (keyPressed && key == 'a') {
playerI.x -= 1.5;
}
if (keyPressed && key == 'd') {
playerI.x += 1.5;
}
spawnZombie(random(0, 1350), random(0, 755));
}