Workshop › Candy Crush-style Match 3 › Step 20 of 29
Each frame of the falling phase, every drop gets FALL pixels smaller, down to 0. Only when no gem is still in the
air has the fall ended; then the cascade check runs as before.
```js
const FALL = 8 // pixels a gem falls per frame
if (phase === 'falling') {
let moving = false
for (let r = 0; r < N; r++) {
for (let c = 0; c < N; c++) {
drop[r][c] = Math.max(0, drop[r][c] - FALL)
if (drop[r][c] > 0) moving = true
}
}
if (moving) return
```Math.max(0, drop - FALL) takes 8 off but never goes below 0.moving starts false and becomes true if any gem is still above its place.update stops there; once everything has landed, the cascade check below runs.COLORS write FALL.update, at the top of the 'falling' block, above the // Landed... comment, write the lines shown.Skills: The game loop, Game states
← Where a gem came from Out from under the top →