CS50 in Arabic Session 1 Project (Option 1): The Bug Chaser (Survival Game)
Welcome to your first project challenge! In this option, you’ll be putting your logic to the test by building a high-stakes survival game. You are a programmer trapped inside a complex codebase, and your goal is simple: stay alive as long as possible while a persistent "Bug" hunts you down.
This project will help you master keyboard controls, homing logic, and how to use variables to track your success. Let’s get coding!
Resource:
If you need help finding specific blocks or understanding exactly what each one does, check out Scratch Reference: This is an interactive tool built specifically to help you search, filter, and understand every single Scratch block. If you’re ever unsure which block to use for your logic, this is your best friend!
Follow these steps to build your game. Remember: the goal isn't just to finish, but to understand how the logic works!
Step 1: Choose Your Characters (Sprites)
In Scratch, every object is a "Sprite." Open the Sprite Library and pick your cast:
- The Player: This represents you.
- Suggestions: A person, a cat, or even a laptop.
- The Enemy: This is the "Bug" chasing you.
- Suggestions: A beetle, a ghost, or a red "X" sprite.
- The Backdrop: Where does the game happen?
- Suggestions: "Neon Tunnel" for a tech vibe, or "Stars" for a space-coding theme.
Step 2: Programming the Player (Keyboard Control)
We want the player to move whenever we press the arrow keys. We will use Conditionals (If-Then) to check for key presses.
Blocks you will need:
When Green Flag Clicked(to start the logic)Foreverloop (to keep checking for keys non-stop)If <key [ ] pressed?> then(The sensing block)Change x by [ ](Left/Right movement)Change y by [ ](Up/Down movement)
The Logic:
- Up Arrow: Change
yby5 - Down Arrow: Change
yby-5 - Right Arrow: Change
xby5 - Left Arrow: Change
xby-5
Pro-Tip: If your sprite is moving too fast, change the number from5to3. If it's too slow, try10!
Step 3: Programming the Bug (The Homing Logic)
The Bug needs to find you no matter where you go. We use Motion blocks to make it "track" your position.
Blocks you will need:
Point towards [Player Sprite]Move [ ] steps
The Logic:
Inside a Forever loop, tell the Bug to Point towards [Player] and Move 2 steps.
Choice Level (Pick One):
- Option A (The Predator): The bug follows you perfectly.
- Option B (The Drifter): Inside the loop, add a
turn pick random (-10) to (10) degrees. This makes the bug move unpredictably and "wobble" as it chases you.
Step 4: The Score & The Game Over
How long can you survive? We need a Variable to track time.
- Go to the Variables category and click "Make a Variable." Name it
Score. - Start the Score: Under the Green Flag,
Set Score to 0. - Increase over time: Use a
Foreverloop with aWait 1 secondsblock followed byChange Score by 1. - The Crash: We need to stop the game if the Bug catches you.
- Add this inside your Bug's script:
If <touching [Player]?> then [Stop All].
- Add this inside your Bug's script:
Step 5: Make it Your Own (Creative Choices)
To make your game unique, try adding one of the following features:
- Size Change: Every time the score reaches 10, make the Bug grow slightly larger using the
Change size by [10]block. - Sound Effects: Add a "boop" sound that plays every time the score increases, or a "crash" sound when the game ends.
- Difficulty: Duplicate the Bug sprite! Now you have two bugs chasing you at once.
Checklist for Submission
- Does the player move with all 4 arrow keys?
- Does the Bug follow the player automatically?
- Does the Score increase every second?
- Does the game stop when they touch?
Session Recording
If you need to review any part of the explanation while working on your project, you can watch the full recording here: Watch the Session on YouTube
In this session, we covered the foundations of Computer Science, the Binary system, and how to take your first steps with Scratch.
Remember: "Programming isn't just about writing lines of code; it's about the art of solving problems." Can't wait to see what you build!
Member discussion