WHITE = (255, 255, 255)
LIGHT_GREEN = (160, 255, 160)
GREEN = (0, 255, 0)
DARK_GREEN = (0, 100, 0)
RED = (255, 0, 0)
BLACK = (0, 0, 0)
Directions
UP = 'up'
DOWN = 'down'
LEFT = 'left'
RIGHT = 'right'
def draw_grid(surface):
"""Draws grid lines on the surface."""
for x in range(0, SCREEN_WIDTH, CELL_SIZE):
pygame.draw.line(surface, LIGHT_GREEN, (x, 0), (x, SCREEN_HEIGHT))
for y in range(0, SCREEN_HEIGHT, CELL_SIZE):
pygame.draw.line(surface, LIGHT_GREEN, (0, y), (SCREEN_WIDTH, y))
def random_position():
"""Generates a random position within the grid."""
x = random.randint(0, (SCREEN_WIDTH - CELL_SIZE) // CELL_SIZE) * CELL_SIZE
y = random.randint(0, (SCREEN_HEIGHT - CELL_SIZE) // CELL_SIZE) * CELL_SIZE
return x, y
def game_over(surface, score):
"""Displays the game over screen."""
font = pygame.font.Font(None, 72)
game_over_text = font.render('Game Over', True, RED)
score_text = font.render(f'Score: {score}', True, WHITE)