def drawBox(boxx, boxy, color, pixelx=None, pixely=None): # draw a single box (each tetromino piece has four boxes) # at xy coordinates on the board. Or, if pixelx & pixely # are specified, draw to the pixel coordinates stored in # pixelx & pixely (this is used for the "Next" piece). if color == BLANK: return if pixelx == None and pixely == None: pixelx, pixely = convertToPixelCoords(boxx, boxy) pygame.draw.rect(DISPLAYSURF, COLORS[color], (pixelx + 1, pixely + 1, BOXSIZE - 1, BOXSIZE - 1)) pygame.draw.rect(DISPLAYSURF, LIGHTCOLORS[color], (pixelx + 1, pixely + 1, BOXSIZE - 4, BOXSIZE - 4))
drawBox() function draws a single box on the screen. The function can receive
boxy parameters for board coordinates where the box should be drawn. However, if the
pixely parameters are specified, then these pixel coordinates will override the
boxy parameters. The
pixely parameters are used to draw the boxes of the "Next" piece, which is not on the board.
pixely parameters are not set, then they will be set to
None by default when the function first begins. Then the if statement on line 8  will overwrite the
None values with the return values from
convertToPixelCoords(). This call gets the pixel coordinates of the board coordinates specified by
The code won’t fill the entire box’s space with color. To have a black outline in between the boxes of a piece, the
top parameters in the
pygame.draw.rect() call have
+ 1 added to them and a
- 1 is added to the
height parameters. In order to draw the highlighted box, first the box is drawn with the darker color on line 10 . Then, a slightly smaller box is drawn on top of the darker box on line 11 .