Session 445 minutes

Session 4: Mini Capstone - Mars Rover Exploration Game

Learning objective: Consolidate Sessions 1-3 into a full Mars Rover game with sound effects, scoreboards, and health bars.

Theory & practice

🪐 Lesson 4: The Mars Rover Expedition Project

🚀 Mission to Mars

Congratulations on finishing the first stage of the course!

In this project, we combine everything we have learned to build a game where you control a robot exploring Mars.

You will use:

  • Motion blocks.
  • Loops.
  • Variables.
  • if ... then conditions.
  • Collision sensing.
  • The keyboard to control a sprite.
Mission: Drive the Mars Rover to collect energy rock samples while avoiding dangerous craters on the surface of Mars.

🎯 Project objectives

After finishing, you will be able to:

  • Control a sprite with the keyboard.
  • Use loops to keep the game running.
  • Use variables to store score and energy.
  • Use conditions to detect objects.
  • Build a game with a clear goal and rules.

1. Setting up the game

Mục Trọng Tâm

Sprites

Create or choose three sprites:

SpriteRole
Mars_RoverThe robot the player controls
Energy_RockThe item to collect
CraterThe obstacle to avoid
Mục Trọng Tâm

Backdrop

Choose a backdrop showing the surface of Mars or outer space.

You can add:

  • A research station.
  • Marker flags.
  • Rocks and volcanic craters.
  • A mission message.

2. Creating the variables

Create three variables:

text
Score
Energy
Time

What each variable means:

  • Score: the number of rock samples collected.
  • Energy: the robot's remaining energy.
  • Time: the time left to finish the mission.

When the game starts:

text
when green flag clicked
set [Score] to [0]
set [Energy] to [100]
set [Time] to [60]
go to x: 0 y: 0

3. Driving the Mars Rover

The Mars Rover must check the keyboard continuously:

text
when green flag clicked
forever
    if <key [up arrow] pressed?> then
        change y by 5
        change [Energy] by -1

    if <key [down arrow] pressed?> then
        change y by -5
        change [Energy] by -1

    if <key [right arrow] pressed?> then
        change x by 5
        change [Energy] by -1

    if <key [left arrow] pressed?> then
        change x by -5
        change [Energy] by -1

Every move uses up some energy, so the player needs to find a short, safe route.

4. Collecting energy rocks

Program the Energy_Rock sprite:

text
when green flag clicked
go to random position
show

forever
    if <touching [Mars_Rover]?> then
        change [Score] by 1
        change [Energy] by 10
        play sound [Collect]
        go to random position

When the Mars Rover touches a rock:

  • Score increases by 1.
  • Energy increases by 10.
  • The rock appears in a new place.

5. Avoiding craters

Program the Mars Rover to detect obstacles:

text
forever
    if <touching [Crater]?> then
        play sound [Alarm]
        change [Energy] by -20
        move -20 steps
        say "Careful! Deep crater." for 2 seconds

If the rover drives into a danger zone, it loses energy and must back away.

6. Building a countdown timer

text
when green flag clicked
set [Time] to [60]

repeat 60
    wait 1 seconds
    change [Time] by -1

After 60 seconds, the Time variable reaches 0.

7. Winning and losing

Mục Trọng Tâm

Mission complete

The player wins after collecting 5 rock samples:

text
if <Score ≥ 5> then
    say "Mission complete!" for 3 seconds
    stop all
Mục Trọng Tâm

Out of energy

text
if <Energy ≤ 0> then
    say "The Mars Rover is out of energy!" for 3 seconds
    stop all
Mục Trọng Tâm

Out of time

text
if <Time = 0> then
    say "Time's up!" for 3 seconds
    stop all

Put these conditions inside a forever loop so the game keeps checking its state.

8. The complete rules

  1. 1The player has 60 seconds to finish the mission.
  2. 2Use the arrow keys to drive the Mars Rover.
  3. 3Collect 5 rock samples to win.
  4. 4Every move uses up energy.
  5. 5Collecting rocks restores energy.
  6. 6Touching a crater costs a lot of energy.
  7. 7The game ends when you win, run out of time or run out of energy.

🧪 Project check

Before you finish, check that:

  • The Mars Rover moves correctly in all four directions.
  • Score starts at 0.
  • Energy starts at 100.
  • The countdown goes down once every second.
  • The rock moves to a new place after being collected.
  • Touching a crater reduces energy.
  • The game stops correctly when you win or lose.
  • Clicking the green flag restarts the game.

🧩 Extension challenges

You can upgrade the game by:

  • Adding more craters.
  • Speeding up after reaching 3 points.
  • Adding special energy batteries.
  • Creating several difficulty levels.
  • Making the craters move.
  • Adding an instructions screen before playing.
  • Saving the high score in a new variable.

Example of increasing the difficulty:

text
if <Score = 3> then
    say "Warning: a Martian storm is coming!" for 2 seconds
    speed up the obstacles

✅ Part 1 summary

In the Mars Rover Expedition project, you combined:

  • Motion to control the robot.
  • Loops to keep the game running.
  • Variables to store score, energy and time.
  • Conditions to handle collisions, winning and losing.
  • Logical thinking to build complete game rules.
🌟 You are ready for the Part 1 quiz. Play the project again and explain what each group of blocks does before you start the quiz.
Mục Trọng Tâm

Quick questions

  1. 1Why should the win and lose conditions be inside a loop?
  2. 2When does the Energy variable change?
  3. 3What happens when the Mars Rover touches a crater?
  4. 4Which feature would you add to make the game more fun?

Ready to test your knowledge?

Open the dedicated exam room to answer questions and review your results.

Part 1 Mastery Quiz: Scratch Logic & Core Blocks →14 questions · 15 minutes