MCPcopy Create free account
hub / github.com/Mrinank-Bhowmick/python-beginner-projects / draw

Method draw

projects/Tetris Game/tetrisGame.py:123–151  ·  view source on GitHub ↗

Draw the grid and the current piece

(self, screen)

Source from the content-addressed store, hash-verified

121 self.lock_piece(self.current_piece)
122
123 def draw(self, screen):
124 """Draw the grid and the current piece"""
125 for y, row in enumerate(self.grid):
126 for x, cell in enumerate(row):
127 if cell:
128 pygame.draw.rect(
129 screen,
130 cell,
131 (x * GRID_SIZE, y * GRID_SIZE, GRID_SIZE - 1, GRID_SIZE - 1),
132 )
133
134 if self.current_piece:
135 for i, row in enumerate(
136 self.current_piece.shape[
137 self.current_piece.rotation % len(self.current_piece.shape)
138 ]
139 ):
140 for j, cell in enumerate(row):
141 if cell == "O":
142 pygame.draw.rect(
143 screen,
144 self.current_piece.color,
145 (
146 (self.current_piece.x + j) * GRID_SIZE,
147 (self.current_piece.y + i) * GRID_SIZE,
148 GRID_SIZE - 1,
149 GRID_SIZE - 1,
150 ),
151 )
152
153
154def draw_score(screen, score, x, y):

Callers 1

mainFunction · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected