In this post you’ll learn how to build a simple game using Scratch, the block-based programming language designed for learning to code. The instructions are not 100% complete, so you’ll need to solve problems yourself, as they arise.

Getting Started

You can use Scratch without an account, but it makes it harder to save your work. So, let’s get started by heading to https://scratch.mit.edu and signing up:

Once your account is set up, click on the Create link in the main menu:

Scratch Basics

You should now find yourself in the Scratch editor, which has the following key features:

Give your project a name (top left), and then note the different features highlighted in the image above. We’ll build our game by dragging instructions into the script editor.

Let’s get started by creating controls to move our sprite around the stage, beginning with the right arrow. Find the instructions shown below, and drag them out into the script editor, snapping them together to make a stack:

Now press the right arrow key on your keyboard and check that your sprite moves to the right.

Try and find the next costume instruction and snap it to the end of your block. What changes when you press the right key?

Now build the rest of your arrow key instructions (you can right click on the top of a stack and duplicate it to save time):

Try your keys and see what happens. You’ll notice that as you move, your character flips upside down. You can add in a rotation control block to each arrow stack to improve this:

Moving On

Right, we’ve got the basic controls, so now we can add some game elements. Firstly, use the Shrink function to reduce the size of your sprite:

Next, add a new sprite, into which you can draw a black maze with a green circle at the end:

Now we need to code our outcomes (losing and winning) into our first sprite:

Can you read the code instruction by instruction to work out what it does?

Let’s add a scoreboard, so we can keep track of our progress. To do this, make a new variable called Score, under Data:

And then add two instructions to our win/lose logic:

And there we have it, a simple maze game that keeps score. From here there are countless ways to make it harder (e.g. include different mazes, make the sprite bigger on each level, make the maze move, add enemies, etc).

Hopefully you’ve succeeded, but if not, or if you want to dig around inside for answers, try my version, which is embedded below:

The video screencast below does a great job of showing this process, with a few minor tweaks:

Happy coding!