Set up Scoring

(Step 7/9) Set up a scoring system.

1. Go to the room.js file and put a setupCharacters function in the onInit function.

code/client/src/game.js

g.setupCharacters("team");


2. In the game.js file we need to put an addCharacters function in the init function.

code/client/src/game.js

g.addCharacters("team")


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

code/client/src/game.js

g.getCharacters("team")


4. Go into our room.js file in the onInit function and use a createACharacter function to create our team character.

code/server/rooms/room.js

g.createACharacter('team',  'team',  { x:  10000, y:  10000, name:  'Level', score:  1  });


5. In the room.js file in the onInit function in the third createALocation function that we wrote, we’ll tell the score to up, and the difficulty to increase.

code/server/rooms/room.js

let team = g.getACharacter('team',  'team')
team.score +=  1
g.getAllCharacters('enemy', enemy =>  { g.deleteACharacter('enemy', enemy.id)  })
for  (i =  0; i < team.score +  15; i++)  { g.createACharacter('enemy', g.nextCharacterId('enemy'),  { x: Math.floor((Math.random()  *  500)  +  1), y: Math.floor((Math.random()  *  1900)  +  1), right:  true  })  }


Download your zip, and upload it to blobbert.io, and you should be able to complete levels for score!


Set up Name Tags
Set up Co-op play

Need Help?

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

Click Here for Help