Skip to content

piece.js

addyh edited this page Nov 15, 2023 · 1 revision

Piece Class

  • Properties

    • Int this.shape -- A number 0-6 representing the shape of the piece
    • Object this.pos - Int .x, .y -- The x, y coordinates of the piece on the board
    • Object this.color - Int .r, .g, .b -- The color of the piece
    • Array this.matrix -- The (4x4) matrix of the piece (0s and 1s)
    • Bool this.atBottom -- Is the piece at the bottom of the board?
    • Board this.board -- A reference to the Board that this piece is on
  • Methods

    • draw() -- Draw this piece to the screen
    • lower() -- Call goDown() if it has been (board.dropInterval) milliseconds
    • goDown() -- Drop the piece by 1 block
    • move(Int where) -- Move the piece left (-1) or right (1)
    • Matrix rotate() -- Try to rotate the piece
    • Bool canRotate(Array rotatedMatrix) -- Is rotatedMatrix a valid rotation?
    • Bool canGoDown() -- Can the piece go down?
    • Bool canMove(Int where) -- Can the piece move left/right?
    • Int atEdge() -- Is the piece at the far left (-1) or right (1) edge of the board, or not (0)?
    • Int farRight(Array pieceMatrix) -- Returns the pixel value of the far right edge of the board
    • Int farLeft(Array pieceMatrix) -- Pixel value of the far left of the board
    • Int farBottom() -- Pixel value of the far bottom of the board

Main Sketch File

Classes

Misc. functions

Clone this wiki locally