criticjae.blogg.se

Tetris pieces
Tetris pieces













# Rotates the array and repositions the piece to where it is now Pov = np.array( for k in np.swapaxes(pov, 1, 2)]) Pov = np.array( = pos, arr = pos)) for pos in coords]) # The straight piece has a 4x4 array, so it needs seperate codeĪrr = top_left + np.array( for y in range(4)] for x in range(4)])

tetris pieces

If current_piece != "I" and current_piece != "O":Īrr = coords - 1 + np.array( for y in range(3)] for x in range(3)]) # arr is the array of nearby points which get rotated and pov is the indexes of the blocks within arr

Tetris pieces code#

In the code below, we first check if the user wants to swap the current piece with the held piece using the switch variable. A piece that is held is such a way is available to be used in the future by swapping it with the current piece. In Tetris, you can press a certain key to hold a piece.

tetris pieces

We have a while loop where at every iteration we place a new piece in the game. Def display(board, coords, color, next_info, held_info, score, SPEED):īorder = np.uint8(127 - np.zeros())īorder_ = np.uint8(127 - np.zeros())













Tetris pieces