Day 5 — Pygame (Day 2) + Gallery Walk
Finish your game · Polish it · Show it off
⬇ Today's slides (PDF)Schedule
| Time | Activity |
|---|---|
| 0:00 – 2:00 | Continue building and polishing your game |
| 2:00 – 2:30 | Gallery walk — play each other's games |
| 2:30 – 3:00 | Save your code, wrap up |
Finishing Touches
Use the first two hours to make your game feel complete. Prioritize in this order:
- Make sure the game can be won or lost (a clear ending)
- Display the score on screen
- Add a game-over screen so the player knows when it's done
- Then add anything extra from the stretch goals
Common Finishing Pieces
These drop into the update() and draw() functions from your Day 4 template — you're extending the same functions, not writing new ones. Remember the rule: any variable a function changes must be on that function's global line.
Game Over Screen
# --- With your other variables, up near the top ---
game_over = False # becomes True when the player loses
# --- Inside update(): flip game_over, and handle restarting ---
def update():
global game_over, score # we change both, so list them here
# ...when the player loses (missed an object, ran out of lives, ...):
game_over = True
# keys is already read inside update(); R restarts once the game is over
if game_over and keys[pygame.K_r]:
score = 0
game_over = False
# reset your other variables here too (obj_y, lives, ...)
# --- Inside draw(): show the message when game_over is set ---
def draw():
if game_over:
screen.fill(BLACK) # clear before drawing the game-over message
# font.render() makes an image of text — (text, antialiasing, color)
msg = font.render(f"Game Over! Score: {score}", True, WHITE)
restart_msg = font.render("Press R to play again", True, YELLOW)
# Centering trick: middle of the screen, then shift left by half the text width
screen.blit(msg, (WIDTH // 2 - msg.get_width() // 2, HEIGHT // 2 - 40))
screen.blit(restart_msg, (WIDTH // 2 - restart_msg.get_width() // 2, HEIGHT // 2 + 20))
Start Screen
started = False # False until the player presses a key
# A separate little loop that runs BEFORE the main loop (before "while running:").
# It keeps showing the start screen until started becomes True. Because it's its
# own loop — not update()/draw() — no global is needed here.
while not started:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.KEYDOWN: # any key press flips started to True
started = True
screen.fill(BLACK)
# Render text as image objects, then blit them onto the screen
title = font.render("My Awesome Game", True, YELLOW)
prompt = font.render("Press any key to start", True, WHITE)
# Center each text image horizontally and position them vertically
screen.blit(title, (WIDTH // 2 - title.get_width() // 2, HEIGHT // 2 - 40))
screen.blit(prompt, (WIDTH // 2 - prompt.get_width() // 2, HEIGHT // 2 + 20))
pygame.display.flip() # push everything we drew to the actual screen
clock.tick(60) # limit to 60 frames per second
Background Music
# Add with your other setup, before the main loop (needs a .wav or .mp3 file)
pygame.mixer.music.load("music.mp3")
pygame.mixer.music.set_volume(0.5)
pygame.mixer.music.play(-1) # -1 means loop forever
Increasing Difficulty Over Time
# Inside update() — recompute the speed each frame as the score climbs
def update():
global obj_speed # we reassign it, so list it here
obj_speed = 4 + score // 5 # objects fall faster every 5 points
Stretch Goals
- Add a lives system — 3 lives, lose one for each miss, game over at 0
- Track a high score across multiple rounds of the same session
- Add animated sprites (swap images each frame to create animation)
- Add particle effects when the player catches something
- Add a pause button (press P to pause / unpause)
- Boss challenge: Save the high score to a file so it persists even after closing the program
Way Ahead? Capstone Challenges
If your game is already polished, pull the whole week together.
Combine Your Week
Wire the days together in one program:
- Pull live data from a Day 2 API and show it inside your game (a weather-based background, a real Pokémon as an enemy).
- Log every game's final score to a file, then chart your session's high scores with matplotlib (Day 3).
- Add a start menu that lets the player pick which of your games to play.
Gallery Walk — 2:00 to 2:30
Leave your game running on your screen. Walk around and play everyone else's games. No presentations — just explore.
- Try to beat someone else's high score
- Ask "how did you make that?" if something surprises you
- Take note of any feature you wish your game had
Take Your Code Home — 2:30 to 3:00
Option A — Email it to yourself
Attach your game.py file (and any sprites/sounds) to an email and send it to yourself.
Option B — USB Drive
Copy your entire project folder to a USB drive. Include:
- Your
game.pyfile - The
sprites/folder - Any sound files you used
Option C — Push it to GitHub (best)
If you set up Git on Day 1, this is the safest way to take your code home — it lives online and you can pull it onto any computer later. From your project folder:
git add . # gather up all your changes
git commit -m "Final camp project" # save a snapshot
git push # upload it to GitHub
No repo yet? Make one at github.com (New repository), then git clone it, drop your files in, and run the three commands above. Note: GitHub requires two-factor authentication, so turn on 2FA when you make the account.
To run it at home
# Install Python from python.org (free)
# Then install pygame:
pip install pygame
# Then run your game:
python game.py
The Rest of the Python World
Games were just the start. The same language you learned this week powers a huge range of real work — here's where you can take it next:
- Web & servers — frameworks like Flask, Django, and FastAPI build real websites and web servers.
- APIs — pull live data from other services (like the Day 2 requests), or build your own API for others to use.
- Automation — short scripts that rename files in bulk, scrape websites, send emails, or tidy up spreadsheets.
- Data science — pandas and NumPy crunch huge datasets; charting builds on the Day 3 matplotlib work.
- AI & machine learning — scikit-learn, PyTorch, and TensorFlow train models that recognize images, predict, and generate text.
- Apps & bots — desktop apps with a GUI, or Discord bots that live in a server and respond to commands.