Workshop › Angry Birds-style Slingshot › Step 17 of 47
When is a shot over? When nothing has moved for a while. calm counts the frames in a row in which no body is
moving; any movement sets it back to 0.
```js
let calm // frames everything has been still
calm = 0
function update() {
step()
if (state !== 'flying') return
// Wait until everything has stopped for a second before the next bird.
const moving = bodies.some((b) => Math.abs(b.vx) > 0.1 || Math.abs(b.vy) > 0.3)
calm = moving ? 0 : calm + 1
}
```calm starts at 0 in reset and again at each launch.bodies.some(f) is true if f is true for at least one body. Math.abs drops the sign, so a speed of -3
counts as 3.moving ? 0 : calm + 1 picks the first value when moving is true, otherwise the second.let state write let calm.calm = 0 in reset (under state = 'aiming') and in launch (under state = 'flying').update, under step(), write the four new lines.Skills: Game states
← Gone off the screen The next bird →