Workshop › Mario-style Platformer › Step 33 of 37
When the last life is lost the game ends. A state variable says what the game is doing: 'playing', 'over' (and
later 'won'). Only while playing does update change anything.
```js
let state // 'playing', 'won' or 'over'
state = 'playing'
if (lives === 0) state = 'over'
else loadLevel()
if (state !== 'playing') return
```loadLevel sets state = 'playing'.die: with no lives left the state becomes 'over'; otherwise the level restarts.update returns at once unless playing, so the game freezes.let coyote write let state ...; at the end of loadLevel, write state = 'playing'.die, replace loadLevel() with the two lines.if (state !== 'playing') return the first line of update.Skills: Game states
← Squashed enemies are gone Play again →