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
+18 -1
View File
@@ -1,6 +1,19 @@
import pygame
import settings
def get_fall_interval(score):
"""
Calculate the fall interval based on the current score.
"""
base_interval = 1000 # Base interval in milliseconds
decrease_per_1000_points = 50 # Decrease in ms per 1000 points
min_interval = 100 # Minimum interval in milliseconds
# Calculate the fall interval
interval = base_interval - (score // 400) * decrease_per_1000_points
# Ensure the interval doesn't go below the minimum
return max(interval, min_interval)
#game states
def draw_text(surface, text, size, x, y, color):
@@ -11,6 +24,7 @@ def draw_text(surface, text, size, x, y, color):
surface.blit(text_surface, text_rect)
class Grid():
def __init__(self, rows, cols, cell_size):
self.cell_size = cell_size
@@ -63,4 +77,7 @@ class Grid():
cleared_rows = len(self.grid) - len(new_grid)
self.grid = [[0] * self.cols for _ in range(cleared_rows)] + new_grid
settings.game_score += 100 * cleared_rows
if cleared_rows >= 4:
settings.game_score += 100 * cleared_rows + 100
else:
settings.game_score += 100 * cleared_rows