281 width, height = self.swapchain_extent
282 if width <= 0
or height <= 0:
285 self.
background.set_uniform(0, 0.0, 0.0, float(width), float(height))
288 cell_size = max(16, min((height - 100) // (BOARD_HEIGHT + 1), (width - 260) // (BOARD_WIDTH + 2)))
289 board_width = BOARD_WIDTH * cell_size
290 board_height = BOARD_HEIGHT * cell_size
291 left = max(24, (width - board_width) // 2 - 100)
292 top = max(50, (height - board_height) // 2)
293 for board_y, row
in enumerate(self.
grid):
294 for board_x, color
in enumerate(row):
297 self.
clear_block.
draw(left + board_x * cell_size, top + board_y * cell_size, width=cell_size, height=cell_size)
299 self.
_draw_cell(color, board_x, board_y, left, top, cell_size)
301 for cell_x, cell_y
in self.
cells:
303 panel_x = left + board_width + 28
304 self.draw_text(
"2D TETRIS", panel_x, top, self.
font, mx.Color(255, 245, 180))
305 self.draw_text(f
"Score {self.score}", panel_x, top + 54, self.
font)
306 self.draw_text(f
"Lines {self.lines}", panel_x, top + 88, self.
font, mx.Color(180, 225, 255))
307 self.draw_text(f
"Level {self.level}", panel_x, top + 122, self.
font, mx.Color(180, 255, 190))
308 self.draw_text(
"Next", panel_x, top + 182, self.
font, mx.Color(255, 245, 180))
309 preview_cell = max(12, cell_size * 3 // 5)
311 preview_min_x = min(cell_x
for cell_x, _
in preview_cells)
312 preview_min_y = min(cell_y
for _, cell_y
in preview_cells)
313 for cell_x, cell_y
in preview_cells:
314 self.
blocks[self.
next_color].
draw(panel_x + (cell_x - preview_min_x) * preview_cell, top + 220 + (cell_y - preview_min_y) * preview_cell, width=preview_cell, height=preview_cell)
315 self.draw_text(
"Arrows: move / rotate", panel_x, top + 340, self.
font)
316 self.draw_text(
"Space: hard drop", panel_x, top + 374, self.
font)
318 self.draw_text(
"GAME OVER", left + cell_size, top + board_height // 2 - 24, self.
font, mx.Color(255, 100, 100))
319 self.draw_text(
"Press R to restart", left + cell_size, top + board_height // 2 + 14, self.
font, mx.Color(255, 255, 255))