1. In room.js
Create an attachTo()
function inside the onJoin()
function to add a health bar
code/server/rooms/room.js
g.attachTo('players', client.sessionId, {
name: 'healthBar',
x: -50,
y: 40,
width: 100,
height: 10,
type: 'bar',
filled: 100
});
2. In room.js
, Create a handleCollision()
function inside the onUpdate()
function so that our health bar will update when we collide with zombies.
code/server/rooms/room.js
g.handleCollision('players', 'zombies', (player) => {
if (player.healthBar.filled > 0) {
player.healthBar.filled -= 0.1;
}
});
Download your zip, and upload it to blobbert.io, and you should have a background!