Workshop › Angry Birds-style Slingshot › Step 43 of 47
startLevel(n) builds level n and does everything reset did except the score, so the score can carry on from
level to level. reset now only zeroes the score and starts level 0.
```js
let level
function startLevel(n) {
level = n
bodies = LEVELS[n].map(([kind, x, y, w, h]) => body(kind, x, y, w, h))
bird = null
birdsLeft = 3
aim = { angle: -0.6, pull: 50 }
dragging = false
state = 'aiming'
calm = 0
}
function reset() {
score = 0
startLevel(0)
}
```startLevel(n) takes a parameter: the number of the level to build, used as LEVELS[n].reset without score = 0, plus level = n.reset sets the score to 0 and calls startLevel(0).let dragging write let level.reset into startLevel(n) as shown (add level = n, use LEVELS[n], remove score = 0), and write the
new reset under it.Skills: Functions, Game states
← Three levels of data On to the next level →