CMPSC101 :: Fall 2025
Assigned: 21st November 2025
Due and Expiration date: End of class (Cut off due date and time).
Ready to create your own games? In this activity, you will discover the exciting world of game development using Pygame, a popular Python library for creating 2D games. Through hands-on tutorials, you will learn how game loops work, how to handle user input, and how to bring graphics to life on screen! 🎨
This activity is designed to give you a quick introduction to game development concepts without getting bogged down in complex code. You will follow two guided tutorials that walk you through creating simple but complete games using copy-and-paste techniques. The goal is to see and understand what makes games work!
Pygame is a Python library that makes game development accessible and fun. It provides tools for:
- Graphics rendering: Draw shapes, images, and sprites on screen
- Event handling: Respond to keyboard, mouse, and other inputs
- Game loops: Control timing and animation
- Collision detection: Check when game objects interact
- Sound and music: Add audio to your games
- Understand interactive programs: Games respond to user input in real-time
- Learn event-driven programming: A fundamental concept in modern software
- Practice problem-solving: Game logic requires creative thinking
- See immediate results: Visual feedback makes programming rewarding
- Apply programming concepts: Loops, functions, and objects come to life
This activity includes two tutorials that progressively introduce you to Pygame concepts. The first tutorial is a simple interactive game, while the second tutorial guides you through building a (very) basic Space Invaders clone.
In two parts, we will cover two tutorials.
- Part 1:
tutorials/tutorial_01_simple_game.md - Part 2:
tutorials/tutorial_02_space_invaders.md
Tutorial guide: tutorials/tutorial_01_simple_game.md
Working directory (for coding): src/tutorial_01_simple_game/
To create your first interactive Pygame program, your code will be completing the below steps.
- Set up a game window
- Handle keyboard input
- Move a circle on screen
- Understand the game loop
- Use Pygame's drawing functions
What you will learn:
- Basic Pygame initialization
- Event handling and keyboard input
- The game loop pattern
- Real-time updates and rendering
Running the Game
# Make sure you're in the root (main) directory of your project
uv run src/tutorial_01_simple_game/simple_game.py Tutorial guide: tutorials/tutorial_02_space_invaders.md
Working directory (for coding): src/tutorial_02_space_invaders/
Build a simplified version of the classic Space Invaders game:
- Create a player-controlled spaceship
- Spawn and manage enemy invaders
- Implement shooting mechanics
- Handle collisions
- Organize code into multiple modules
What you will learn:
- Multi-file project structure
- Game object classes (Player, Enemy)
- Configuration management
- Module organization
- More complex game mechanics
Running the Game
# Make sure you're in the root (main) directory of your project
uv run src/tutorial_02_space_invaders/main.pyWe will use UV (a fast Python package manager) to manage our Pygame environment. UV makes it easy to install packages and run Python projects.
First, check if UV is installed on your system:
uv --versionIf you see a version number, you're good to go! If not, install UV:
# macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
# Or using Homebrew on macOS
brew install uvcd /path/to/your/activity_09Each tutorial will guide you through using UV to install Pygame and run your games. The tutorials include specific UV commands for each project directory.
For each tutorial, you will:
- Read the tutorial markdown file in the
tutorials/directory - Navigate to the appropriate
src/subdirectory for that tutorial to find the source files - Follow the step-by-step instructions to copy and paste code
- Run your game using UV commands provided in the tutorial
- Observe and understand what the code does
- Experiment by making small modifications (optional but encouraged!)
- Copy and paste carefully: Make sure you copy complete code blocks
- Indentation matters: Python is sensitive to spacing and tabs
- Read the explanations: Understanding is more important than just copying
- Save frequently: Use
Cmd+S(macOS) orCtrl+Sto save your files - Run often: Test your code after each major addition
This is a checkmark assignment. You will receive credit for:
- Completing both tutorials
- Having working game files in both
src/directories - Submitting a thoughtful reflection
Submit the following items to your GitHub repository:
-
Completed game files:
src/tutorial_01_simple_game/simple_game.py- Your working simple gamesrc/tutorial_02_space_invaders/main.py- Space Invaders entry pointsrc/tutorial_02_space_invaders/game.py- Game logicsrc/tutorial_02_space_invaders/config.py- Configuration settings
-
Completed reflection document:
writing/reflection.mdwith thoughtful responses to all questions
🚀 As you work, commit and push regularly using these commands:
git add -A
git commit -m "Complete Tutorial 1: Simple Game"
git pushImportant: After pushing, visit your GitHub repository in a browser to verify your files uploaded correctly!
Students with questions are encouraged to:
- Ask in the course Discord channel - Your classmates might have the same question!
- Attend instructor or TL office hours - Get one-on-one help
- Review Pygame documentation - https://www.pygame.org/docs/
- Check for typos - Most errors come from small copy-paste mistakes
Remember: Game development is challenging but rewarding. Don't get discouraged if something doesn't work the first time!
- Read before you copy: Understand what each code block does
- Test incrementally: Run your code after adding each section
- Pay attention to file names: Make sure you're editing the right file
- Watch for indentation: Python requires consistent spacing
- Have fun: Experiment and make the games your own!
Ready to start? Head to tutorials/tutorial_01_simple_game.md and begin your game development journey! 🚀
Good luck, and enjoy creating your first games with Python and Pygame! 🎮✨
