Workshop › Tower Defense › Step 25 of 42
Now the enemies are a threat: every enemy that walks off the end of the road costs one of your 20 lives. Its hp drops to 0 so no bullet keeps chasing it, and it pays no gold.
```js
let lives
lives = 20
// Walked off the end of the road: it got through. Its hp drops to 0 so no bullet chases it any more.
for (const e of enemies) {
if (pointAt(e.d) === null) {
e.hp = 0
lives -= 1
}
}
ctx.fillText('Gold ' + gold + ' Lives ' + lives, 10, 26)
```' Lives ' starts with two spaces.let gold write let lives; in reset, under gold = 120, write lives = 20.update, write the comment above the end-of-road loop and lives -= 1 under e.hp = 0.draw, add the lives to the top line.Skills: Game states
← Gold for every kill Health bars →