How to write your own computer game

19 Aug 2009

Looking for something to keep a 7-11 year old entertained? Barry Collins has the answer with this guide to writing a fun-packed game

With even the Government admitting parts of the school ICT curriculum are failing to stretch pupils far enough, there's never been a greater need for parents to give their children a helping hand. That's why we've teamed up with teachers and IT education experts to create a series of fun but challenging computing tasks for school children.

Our tailor-made tutorials are designed to stretch your children's IT talents and teach them skills they won't necessarily learn at school - and maybe even teach parents a thing or two. In the second of these tutorials, we explain how a 7-11 year old can create a great game from scratch.

Source the Scratch software

Source the Scratch software

First download the software from the Scratch website (http://scratch.mit.edu). On the site you'll find examples of games and animations created in Scratch, as well as an excellent support section, which includes printable "Scratch Cards" that you keep by the computer to help master the controls. There's also an excellent reference guide that provides a comprehensive list of all the Scratch commands.

Setting the scene

Setting the scene

We're going to create a summer holiday game, set on a beach. Click on the blank Stage box in the bottom right-hand corner, and then select the background tab from the middle panel. Click Import, Nature and select the beach-malibu file. If you have your own holiday beach photos, feel free to choose one from the Pictures folder on your PC. It would be wise to resize large photo files to below 100KB first.

Creating characters

Creating characters

Now we need to create some characters. Characters in Scratch are called Sprites. You'll see that you already have a cat Sprite selected, but he isn't very appropriate for the beach, so right-click on the Sprite 1 icon in the bottom right-hand corner and delete him. Now click on the Choose New Sprite from File Icon (the middle of the three buttons below the beach picture) and select crab1-a from the Animals folder.

Put your child in the action

Put your child in the action

Now it's time to put your child in the game. Take a full-length body shot of your child with a digital camera, and cut out the image in photo-editing software so that only the body is retained (see our guide at www.pcpro.co.uk/links/179photo). Save it as a GIF file. Now Click on the Choose New Sprite from File icon and select the photo of your child. Alternatively, you can select one of the provided images of children from the People folder.

Cutting characters to size

Cutting characters to size

You may notice your characters look relatively huge compared to the beach. Shrink them down by selecting the Shrink Sprite button (highlighted in blue above the beach scene in the photo). Once selected, click on your characters until they look roughly proportional to the above landscape, as we've done with the crab here. Now we're going to show you how to assemble commands to make your characters move and interact.

Establishing controls

Establishing controls

Select the child's Sprite in the bottom right-hand corner and then click the yellow Control button in the top-left corner. Click and drag the When Space Key Pressed button into the middle Scripts panel. Now click Motion in the top left, and drag Point In Direction into the middle panel until it snaps in place beneath When Space Key Pressed. Then drag Move 10 Steps to the bottom of the pile.

Adding navigation

Adding navigation

Use the dropdown menus to change the keys pressed and directions to those shown in the picture. Repeat for all four arrow keys, as shown. Your child's character should now move when you press the arrow keys, but you might notice they flip upside down when moving. Click the tiny Only Face Left-Right button (which is found next to the little thumbnail image of the boy at the top of the screen) to keep him upright.

Make the crab chase the character

Make the crab chase the character

Now we're going to make the crab chase the child. Select the crab sprite in the bottom-right corner and select the commands shown above from the Control and Motion menus. Note that the Forever command wraps around the actions to create a loop, meaning the crab will keep chasing the boy until you press the red stop button. We've changed the move steps from 10 to 2 to slow the crab down. Click the green flag to go.

Give the game some audio

Give the game some audio

Now for some sound effects. Make your child's sprite scream when the crab bites it by adding the commands shown above. Note that the Touching command is found in the Sensing menu. If your PC has a microphone, your child can record their own scream by clicking the Record option from the dropdown menu in the Play Sound command. If not, click on the Sounds tab and choose a sound from the library.

Setting a pause between bites

Setting a pause between bites

To give your child character a chance to get away once the crab bites, we need to make the crab pause after he strikes. From the Control menu select Wait 1 Second and drag it directly below the Play Sound command. Boost the number of seconds to two to give your child a sporting chance of escaping before being bitten again. Now click the green play button and test it out.

Setting the score

Setting the score

How about keeping score of the bites? Click on Variables, then Make A Variable and name it Score. Click OK. Then drag the Set Score and Change Score by commands into the position shown. The score should automatically appear in the game screen. If it doesn't, left-click on the beach Stage in the bottom-right corner and drag Show Variable Score into its script.

Turn on to full screen

Turn on to full screen

To see your game in full screen, click the Presentation Mode button (just below the game screen) and don't forget to save your game with the Save As command at the top of the screen. We've only had space to cover the basics, but you could try adding more characters, a timer or background music. Don't forget that you can share your games with other players by clicking the Share! button at the top of the screen.

Read more

Tutorials