Setup Bullets

Learn how to make a super cool zombie game

1. in game.js, Create bullets using the addCharacters() function inside the init() function.

	g.addCharacters('bullets', 0.5);

2. in game.js, Create loadImage() function to load the image for the bullets.

	g.loadImage('bullets', 'bullet.png');

3. In game.js, Create a getCharacters() function to add the bullets to the game in the create() function.


4. In room.js, Create a setupCharacters() function inside the onInit() function to set them up on the server.


5. In room.js, Create onMessage()method to get our bullets to shoot.

			click: () => {


6. In room.js, in the onMessage() function in the click method that you just created Add code to make the bullets animate and go in the right direction.

			const index = g.nextCharacterId('bullets');
			g.createACharacter('bullets', index, { x: player.x, y: player.y });
			let newCharacter = g.getACharacter('bullets', index);
			g.playAnimation(newCharacter, 'x',
				g.getXTowards(newCharacter, data.x, data.y) * 500, 2000);  
			g.playAnimation(newCharacter, 'y',
				g.getYTowards(newCharacter, data.x, data.y) * 500, 2000);
			setTimeout(() => g.deleteACharacter('bullets',, 2000);

7. In game.js, Make sure your Click Function looks like this.

Now there is only two more things we need to do to make our bullets shoot, first check and make sure your game.js file has a click method that looks like this:


click(x, y) {  
	g.sendAction('click', {x, y});

8. In room.js, add the handleAnimations() function in the onUpdate() function for our bullets.


9. In room.js, Add code to handle the collision and delete the zombies if they collide with the bullets in the onUpdate() function.

	g.handleCollision('bullets', 'zombies', (bullet, zombie) => {

Now you should have working bullets that can kill the zombies when you shoot!

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

Add a Health Bar
Setup Login Screen

Need Help?

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

Click Here for Help