Workshop › Angry Birds-style Slingshot › Step 39 of 47
When a shot has settled, the game decides: no pigs left means the level is won, and every unused bird is worth 1000; pigs left and no birds means lost; otherwise, the next bird. Once it is over, the physics stops.
```js
let state // 'aiming', 'flying', 'won' or 'lost'
function update() {
if (state !== 'flying' && state !== 'aiming') return
...
if (pigs().length === 0) {
score += birdsLeft * 1000 // unused birds are worth a lot
state = 'won'
} else if (birdsLeft === 0) state = 'lost'
else state = 'aiming'
}
```state can now be two more words.update stops everything once the game is won or lost.pigs().length === 0 asks whether any pig is left; the if ... else if ... else picks one of three outcomes.let state comment.update, write the new first line.update, replace state = 'aiming' with the if ... else if ... else.Skills: Game states
← Count the birds The end panel →