gamegrid, falling, Tetrominos, collision and deleting rows, GUI Menus and Score, speeding up, hold function and next tetrominos display

This commit is contained in:
IM23a-bachmannj2
2024-12-19 09:34:18 +01:00
parent 6de87ac002
commit 461d0e57fc
4 changed files with 96 additions and 28 deletions
+21
View File
@@ -60,3 +60,24 @@ class Tetrominos:
"""Move the tetromino to the lowest possible position."""
while not grid.check_collision(self.shape, self.x, self.y + 1):
self.y += 1
def draw_next_tetromino(self, surface):
"""
Draw the next tetromino in the preview window.
"""
surface.fill((0, 0, 0))
cell_size = 30 # Smaller cell size for the preview
x_offset = (surface.get_width() - len(self.shape[0]) * cell_size) // 2
y_offset = (surface.get_height() - len(self.shape) * cell_size) // 2
for row_idx, row in enumerate(self.shape):
for col_idx, cell in enumerate(row):
if cell:
cell_rect = pygame.Rect(
x_offset + col_idx * cell_size,
y_offset + row_idx * cell_size,
cell_size,
cell_size
)
pygame.draw.rect(surface, self.colors[self.shape_number - 1], cell_rect) # Red color for tetromino