You're browsing the old v2.x documentation. This version is no longer maintained. Click here to go the v3.x documentation.

Step 3.2.4: Locking a piece

When a piece can not move further to the bottom, it is locked, which means it becomes part of the playfield.

This routine is very similar to the one where we were checking if the piece overlaps the playfield. We will use the same function to extract individual rows from the shape but this time we use the OR bitwise operator to merge the row of the shape to the row of the playfield. Here is the function:

REM -- Make a piece part of the playfield
PROC lock_piece
  FOR i! = 0 TO 3
    row_no! = \piece_y! + i!
    REM -- Row 23 is the last where we want to do this
    IF row_no! <= 23 THEN
      REM -- Get a row from the piece and merge with playfield
      piece_row = extract_row(\shape, i!, \piece_x!)
      \playfield[row_no!] = \playfield[row_no!] | piece_row

Note that the bitwise OR operator in XC=BASIC is the pipe character (|).