Workshop › Tetris-style Blocks › Step 18 of 32
When the piece cannot fall any more it locks: its blocks are copied into the board, and a new piece appears.
```js
function lock() {
piece.shape.forEach((cells, r) => {
cells.forEach((value, c) => {
if (value) board[piece.y + r][piece.x + c] = value
})
})
spawn()
}
function softDrop() {
if (!tryMove(0, 1)) lock()
}
softDrop()
```lock walks the matrix like drawShape, but writes each filled cell's number into the board instead of drawing it.softDrop tries to move one row down; if that fails (!), the piece has landed and is locked.softDrop().tryRotate write lock and softDrop.loop, replace tryMove(0, 1) with softDrop().Skills: Game states, Arrays and objects
← A random piece at the top One function starts a game →