BrightKidz Library
Subjects
Scratch blocks snapped together to make a catching game Three code blocks are snapped together in a stack on the left, each with a bump underneath and a matching notch on top so they only fit one way round. On the right an apple falls along a dashed line towards a basket waiting below it, which is the game those blocks are building.

Designing a Simple Game with Scratch

About 5 minutes

Scratch is a programming language where the code is colored blocks that snap together like puzzle pieces. You drag them instead of typing them, so you cannot make a spelling mistake — which means the only thing left to get wrong is the thinking, and that is the part worth practicing.

It was made at MIT, it is free, and it runs in a web browser.

The Game You Are Building

Apples fall from the top of the screen. You move left and right with the arrow keys and catch them. Every catch scores a point.

That description is already the whole design. Two characters, two behaviors, one score.

Build It

  1. Start a new project. You will see a cat on the stage. Click the trash can to delete it — you are choosing your own characters.
  2. Add two sprites. Use the "Choose a Sprite" button in the bottom right. Pick a character to play as, then add an apple.
  3. Make the apple fall. Click the apple. From Events drag out when green flag clicked. Under it put a forever block from Control, and inside that put change y by -5 and wait 0.1 seconds.
  4. Send the apple back to the top. Still inside the forever block, add if y position < -170 then, and inside that put go to x: (pick random -200 to 200) y: 150. Now the apple reappears at the top in a new place every time it falls off the bottom.
  5. Move the player. Click your character. Add when green flag clicked, then a forever block containing if key right arrow pressed? then change x by 10 and if key left arrow pressed? then change x by -10.
  6. Add the score. In Variables click "Make a Variable" and call it Score. On your character, after when green flag clicked, add set Score to 0. Then inside its forever block add if touching apple? then change Score by 1 and go to x: (pick random -200 to 200) y: 150 for the apple.

Press the green flag. If apples fall and your character slides sideways, you have a game.

Why forever Is Everywhere

Almost every block above sits inside a forever loop, and that is not an accident. A game is not a list of instructions that runs once — it is a small set of checks repeated many times a second. Has a key been pressed? Has the apple hit the bottom? Are the two sprites touching? Ask those questions fast enough and it looks like a world.

Why does the code for moving your character sit inside a forever block?

Make It Yours

That last one turns a toy into a game. Until something can go wrong, catching apples is not really a challenge.