Start From Scratch!

Create a fun computer game using MITs free coding tool

Scratch is a free, visual programming language and online community developed by the MIT Media Lab. Instead of typing code, kids snap together colorful blocks like puzzle pieces.

In this introduction activity, we will create a simple game where:

  • The player controls a cat with arrow keys

  • The cat chases a star

  • Each time the cat touches the star, the score increases and the star moves somewhere new

Time: 30-45 minutes

Difficulty: Challenging

Age: 7+

What you need…

  1. Computer, laptop, tablet and/or smartphone.

  2. Internet Connection

  3. A Scratch account (optional, but helps for saving projects)

Pro-tip: This activity works best with a larger screen, try avoiding phones and smaller tablets.

Let’s Begin!

Start by watching this short introduction video.

Now let’s start creating.

Step 1. Set Up Your Sprites

Go to scratch.mit.edu and create an account (this allows you to save your progress). Then…

  1. Click “Create” in the top menu

  2. Delete the default cat if you want, or keep it!

  3. Click the Choose a Sprite button:

    • Pick a Cat (if not already there) for the player

    • Pick a Star sprite for the target

    • Optional: Add a fun Backdrop (like "Blue Sky")

Step 2. Control the Cat

Click on the Cat sprite, then add the following blocks:

  1. From Events:

    • when green flag clicked

  2. From Control:

    • forever

  3. Inside forever, add four if blocks from Control:

  4. Inside each if, use Sensing > key [arrow] pressed? and Motion > change x/y by to move.

Example:

  • if key [right arrow] pressed → change x by 10

  • if key [left arrow] pressed → change x by -10

  • if key [up arrow] pressed → change y by 10

  • if key [down arrow] pressed → change y by -10

Your code should look like this:

 Test it! Click the green flag to activate. The cat should now move with arrow keys.

Step 3. Create a Score Variable

Go to the Variables category.

  1. Click Make a Variable, select “for all Sprites”, name it score.

  2. Add:

    • 🟨 when green flag clicked

    • 🟧 set score to 0

Your code should now look like this:

Step 4. Make the Star React

Click on the Star sprite, then add:

  1. 🟨 when green flag clicked

  2. 🟧 forever

    • Inside the forever block:

      • 🔷 if <touching [Cat]>

        • 🟦 go to random position

        • 🟪 Play Sound [collect] until done

        • 🟧 change score by 1

This will teleport the Star, make a sound and update the score every time the Cat touches it.

Your code should look like this:

(remember this code is specific to the “star” sprite, make sure you have it selected and not the cat)

 Test it! Click the green flag to activate. Move the cat to the star. Each time you touch the star it should chime and move. The score counter should be working as well.

Step 5. ⏱️ Add a 30-Second Timer to “Chase the Star”

🧮1st Create a “time” Variable

  1. Go to the Variables category.

  2. Click Make a Variable → name it time.

Then…

Add the following code block to the “Cat” sprite:

  • 🟨 when green flag clicked

  • 🟧 set time to 30

  • 🟧 repeat 30

    • Inside the repeat block:

      • 🟨 wait 1 seconds

      • 🟧 change time by -1

  • After the loop, add:

    • 🟨 broadcast [Time's Up]

    • 🟧 stop [other scripts in sprite]

The entire “Cat” sprite code should look like this:

 Test it! Click the green flag to activate. Move the cat to the star. Each time you touch the star it should chime and move. The score counter should be working as well.

Step 5. Stop the Game When Time Runs Out

🧮1st add a new sprite:

  1. Click “add sprite” → “choose sprite”

  2. Select “Line” and position it in the center of your game window

Then…

Add the following code blocks to the “Line” sprite:

  • 🟨 when green flag clicked

    • 🟪 hide

  • 🟨 when I receive [Time's Up]

    • 🟪 show

    • 🟪 Play Sound [pop] until done

    • 🟦 go to x: [0] y: [0]

    • 🟪 say [Game Over!

The “Line” sprite code should look like this:

Step 6. Play!

Congratulations! You’ve now created a playable video game.

Who can get the highest score?

Key Vocabulary Words and Definitions

  1. Sprite
    Definition: A sprite is a character or object in Scratch that you can program to do things like move, talk, or react.
    Why It’s Important: In “Chase the Star,” the Cat and the Star are sprites. You tell them what to do by attaching blocks to them, like moving or keeping score.

  2. Variable
    Definition: A variable is like a container that holds information, such as a number or word, which can change while your program runs.
    Why It’s Important: The game uses two variables: one to keep track of the player’s score, and one for the timer that counts down from 30 seconds.

  3. Event
    Definition: An event is something that starts a specific action in your program, like clicking a button or pressing a key.
    Why It’s Important: The green flag is an event. When it’s clicked, it tells the game to start running—moving the cat, counting time, and checking for collisions with the star.

Reply

or to participate.