Game programming in Scratch

xwingpicNot much to write about this time round (seems time is getting even more sparse these days…) but I wanted to post a little game created with my son in Scratch.

Usually, Scratch programming gets put on the back burner – I’ve often got other projects in mind and so I tend to neglect Scratch. This half-term, my son asked for an introduction to programming and so game writing was on the cards. We worked through some simple thoughts and it ended up being inspired by the Star Wars films since he’s quite a fan.

I particularly wanted to show how a simple game can be built up incrementally, starting with simple movement of a space ship and then adding asteroids that have to be dodged. These were given a simple animation of top-to-bottom to give an impression of forward movement.

Once this was working, the detection of hits came in. This was relatively easy – I’m always so impressed at how Scratch offers this as standard, particularly as I’ve tried writing this type of game as a late teenager in Forth on my Jupiter Ace. With that, the nearest one could get was redefining the character set to look like the objects being controlled and then deciding if you’re near enough.

The next stage was to add some kind of missile or torpedo. I know there are a number of ways of solving this but my preferred method was to make the spaceship’s x-position into a global variable (Available to all sprites). This is an excellent introduction to variable types, particularly as we forgot to tick the correct box initially.

A simple game like this is an excellent introduction to programming – it ticks all of the boxes of sequential instructions, conditional branching and iteration, with a generous smattering of local and global variables.

Our little game doesn’t have any custom sound effects, or a timer. These are no real challenge to add.

The final file is available to download for anyone who wants to try it.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s