From 6504bb140a71494266c5d1e04ed10ec845e4a726 Mon Sep 17 00:00:00 2001 From: Sean-Randall <166264296+Sean-Randall@users.noreply.github.com> Date: Sat, 24 May 2025 22:53:05 -0400 Subject: [PATCH] Add live score display using pygame --- main.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index ee81ed8..073efeb 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,10 @@ - ---- - -### **Basic Code for `main.py`** -```python import pygame import random # Initialize Pygame pygame.init() +font = pygame.font.SysFont(None, 36) +score = 0 # Game Settings WIDTH, HEIGHT = 600, 400 @@ -32,6 +29,9 @@ running = True while running: screen.fill(BLACK) + score_text = font.render(f"Score: {score}", True, WHITE) + screen.blit(score_text, (10, 10)) + # Event Handling for event in pygame.event.get(): @@ -54,6 +54,7 @@ else: snake.insert(0, new_head) if new_head == food: + score += 1 food = (random.randint(0, WIDTH // GRID_SIZE - 1) * GRID_SIZE, random.randint(0, HEIGHT // GRID_SIZE - 1) * GRID_SIZE) else: