Workshop › Tetris-style Blocks › Step 7 of 32

A list of shapes

What we are doing

All the shapes go in one list, SHAPES. We start with three: the long I, the square O and the T. Every matrix is square, even if it has empty rows: that is what lets us rotate them later. The falling piece takes a copy of the T.

```js
// Each piece is a square matrix; the number is its color. Square matrices rotate around their center.
const SHAPES = [
  [
    [0, 0, 0, 0],
    [1, 1, 1, 1],
    [0, 0, 0, 0],
    [0, 0, 0, 0],
  ],
  [
    [2, 2],
    [2, 2],
  ],
  [
    [0, 3, 0],
    [3, 3, 3],
    [0, 0, 0],
  ],
]

let piece = { shape: SHAPES[2].map((row) => [...row]), x: 3, y: 0 }
```

What it means

Your turn

  1. Under COLORS write the comment and SHAPES with the three matrices.
  2. Change the shape: of piece to SHAPES[2].map((row) => [...row]).

Skills: Arrays and objects

All steps

  1. The well
  2. The board as rows of numbers
  3. Draw one cell
  4. Draw the whole board
  5. The number is the color
  6. A piece is a small grid
  7. A list of shapes
  8. All seven pieces
  9. Does it fit inside the well?
  10. Blocks are in the way
  11. Try, then move
  12. Move with the arrows
  13. Turn a matrix
  14. Turn with Up
  15. Wall kicks
  16. Falling by itself
  17. A random piece at the top
  18. Land and lock
  19. One function starts a game
  20. When the pile reaches the top
  21. Game Over on screen
  22. Play again
  23. Clear full rows
  24. Points for lines
  25. The side panel
  26. Levels
  27. Faster every level
  28. A fair bag of pieces
  29. The next piece
  30. Drop it
  31. The ghost piece
  32. Build it yourself: hold a piece