Add Zombies

Learn how to make a super cool zombie game

Find an Image for the Zombies in Your Game

1. In game.js Use loadImage() function to add some Zombies inside the preload() function.

	g.loadImage('zombies', 'zombie.png');

2. In room.js, Add setupCharacters() in the onInit() function to add zombies.

	g.setupCharacters('zombies', 0.5);

In game.js, Add addCharacters() in the Init() function to add zombies.

	g.addCharacters('zombies', 0.5);

3. In game.js, Add getCharacters() function in the create() function.


4. In room.js, add a setInterval() function to randomly spawn zombies across the map inside the onInit() function.

	setInterval(() => g.createACharacter('zombies',
		g.nextCharacterId('zombies'), {
			x: Math.floor((Math.random() * 2000) + 1),
			y: Math.floor((Math.random() * 2000) + 1)
		}), 2500);

The number at the end will determine how long to wait until it spawns another zombie, and the two 2000 numbers are the bounds for where the zombies should spawn.

5. In room.js, add the follow() function inside the onUpdate() function so that zombies will follow you.

	g.follow('players', 'zombies', 1, 0.1);

You can change the numbers to change the distance the zombies will come to your character, and the speed of the zombies.

Download your zip, and upload it to, and you should have a background!

Setup Camera Follow
Add a Health Bar

Need Help?

Proofread your code, check with your team and classmates, and if you’re still stuck!

Click Here for Help