What You Will Build
Pilot a spaceship through asteroid fields across multiple star-system backdrops. Follow the guide below to build the project, then open the official Raspberry Pi page for starter files, worked examples and extra help.
🍓 This project is on the Raspberry Pi Foundation website. Click the orange button above to access the full guide, starter Scratch project and extension activities on projects.raspberrypi.org.
What You Will Learn
- Implement momentum and inertia using velocity variables
- Detect asteroid collisions and lose lives
- Collect fuel canisters to maintain flight
- Navigate through 3 different space backdrops
- Display speed, lives and fuel as HUD variables
Step-by-Step Guide
- 1Create 3 space backdrops: Near Earth, Asteroid Belt, Deep Space.
- 2Add a spaceship sprite with thrust costume.
- 3Create variables: xVel, yVel, lives (3), fuel (100).
- 4when [up arrow] pressed: change yVel by 1. Left/Right: change xVel by -1/+1.
- 5In forever loop: change x by xVel, change y by yVel. Multiply both velocities by 0.98 (drag).
- 6Add 5 asteroid sprites moving in random directions. If ship touching asteroid: lives -1, flash effect, reset position.
- 7Add 3 fuel canister sprites. If ship touching canister: fuel +30, hide canister.
- 8Fuel decreases by 0.1 each loop. If fuel = 0: stop engines (can't accelerate).
- 9Add a planet destination sprite. When touching: switch to next backdrop, add score.
- 10If lives = 0: show Game Over screen.
Extension Challenges
Finished the main project? Push further:
- Add a black hole sprite that pulls the ship toward it using math each loop.
- Add a shield power-up that makes the ship invincible for 3 seconds.
- Add enemy ships that fly toward the player and shoot projectiles.