Scratch is a great, free, introduction to programming, mainly aimed at children. It's from MIT and is designed to make it easy for anyone to program a computer, it's especially good for simple games and music.
I wrote this introduction after teaching a class of 9 year old kids how to program at a local school. Obviously you should familiarize yourself with Scratch before attempting to teach it!
There's a new, web based, version out and these instructions were written for the older version, but I believe they still mostly apply.
I suggest you start by show a demo of one of the games from the Scratch installation to show what can be achieved (if you select Open... from a new install of Scratch you'll find a bunch of projects to show).
Then show a quick demo of the basic game they are going to develop this session.
Now open Scratch and go through the various bits of the UI, it's helpful to name the various areas so that they know what you're talking about (especially the stage and the blocks palette).
Then demonstrate some of the features:
- Dragging and moving the cat using the mouse (pun intended).
- Making the cat bigger, smaller and duplicating.
- Note the 4 main areas of the screen:
- The Blocks Palette with Motion, Looks etc: going to cover that in a mo.
- The Scripts area: this is where your scripts will run and where you can control the costumes of the sprits, top you can rename (show changing name to cat).
- The Stage (top right): this is where your project runs, note little TV bottom this runs it full screen.
- The Sprint List (bottom right): Lets you pick which sprite you want to work on, or the stage.
- Go through the Blocks Palette tabs one by one; quite quickly as we are going to let them experiment:
- Motion: show you can double click an action to affect the cat.
- Looks: show changing costumes with double click
- Sound: Note that some things don't work just on double click they need to be in a script
- Pen: Leave for now, we're not going to use the pen much.
- Control, Sensing, Numbers and Variables: Leave for a bit.
- Back to the Motion tab for some more details:
- Note that each sprite has a direction, it starts off pointing right.
- Double click on the Move 10 steps. Note that the cat only moved a little bit, that's because the 'stage' is divided into tiny squares (pixels) there are 480 squares left-to-right and 360 top-to-bottom, try changing the 10 to 100 steps and double click, see how it moves about 1/4 of the screen.
- Note that white areas within blocks are places you can type or choose from a list, basically stuff you can change.
- Now turn to 0 (up) and do some steps.
- Also show turning 15 degrees to show it doesn't have to be just right angle turns.
- Show how you can combine blocks by dragging them on top of each other, make the cat dance with something like:
Now get them to open up Scratch and let them play around for a few minutes with the Motion, Looks and Sound tabs; tell them no harm can come, go wild!
Starting their first game
Now we write a script, I run through this with the whole class step by step.
I'm going to write this out in excruciating detail, but after this I'll assume you can put a script together and just show pictures of the finished scripts unless there's a point I'm trying to get across.
- Click New... to create a new project.
- Click on Sprite 1
- Rename it cat.
- Go to the Control tab.
- Note that so far nothing happens unless we double click on the block, now we are going to make stuff happen automatically.
- Note that the yellow 'hats' are always where scripts will start and each sprite can have many scripts.
- Drag the When <space> clicked hat onto scripts [Note Concept: Events]
- Choose right arrow from drop-down.
- Change to Motion tab
- Drag point in direction 90 and snap onto hat.
- Drag move 10 steps and snap onto point in direction.
- Show clicking the green flag to run the scripts.
- Press right a few times.
- Note: Cat gets stuck at the edge.
- Click Duplicate tool
- Drag on the when right arrow pressed hat to create a copy.
- Change right arrow to left arrow.
- Change 90 to -90 (right).
- Click green flag to go.
- Notice cat flips upside down when you go left.
- Use the <-> icon at top of central area to constrain to left/right only.
- Without showing them get them to add up and down arrows.
Changing the background (stage)
That's a bit boring, let's change the background:
- Click 'stage'
- Choose backgrounds tab
- Choose outdoors, brick-wall-1.
Adding an opponent
It's not a very fun game so far, let's add an opponent:
- On bottom right choose the import sprite icon
- Choose animals then bat1-a.
- Rename it to bat.
- Shrink it down a few times with the shrink tool.
Add a script: When (flag) clicked, forever, move 10 steps, if on edge bounce.
Show it working, bit dull it just goes side to side, show the little blue line on the sprite in the middle section, drag it so that it's at some jaunty angle, then the bat will bounce around all over the stage.
Changing costumes
Bat looks odd, it's not moving its wings.
- Go to Costumes tab and import the bat1-b costume.
- Show how clicking from one to the other changes the look.
- Back to Scripts
- From Looks drag in next costume block below move 10 steps.
- Try it
- Hmm, wings moving too quickly, from Control tab drag in a wait block and set to 0.05 seconds.
Get the kids to get the cat to walk properly by adding in next costume blocks for each direction (when I did it the cat already had the second costume).