Visual Studio Code
Python 3.11
Pygame
Make sure 3.11 is installed. Then in terminal:
py -3.11 --version
If that works, you’re good.
In VS Code:
Open Extensions (left sidebar)
Install Python (by Microsoft)
Make a folder:
racing-game
Open it in VS Code
(File → Open Folder)
Press:
Ctrl + Shift + P
Type:
Python: Select Interpreter
Choose:
Python 3.11
This step fixes 90% of problems
Open terminal in VS Code:
Terminal → New Terminal
Run:
py -3.11 -m pip install pygame
Create:
main.py
Paste this starter (this WILL run):
import pygame
import sys
pygame.init()
WIDTH = 400
HEIGHT = 600
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Racing Game")
clock = pygame.time.Clock()
player_x = 175
player_y = 500
player_speed = 5
running = True
while running:
screen.fill((50, 50, 50))
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
player_x -= player_speed
if keys[pygame.K_RIGHT]:
player_x += player_speed
pygame.draw.rect(screen, (255, 0, 0), (player_x, player_y, 50, 100))
pygame.display.update()
clock.tick(60)
pygame.quit()
sys.exit()
press the ▶️ Run button in VS Code