Operation Manual

A beginner’s guide to Scratch
44
In the script for the barrier, I have used a “when [ ] key pressed” block from
Control, with its value set to “t. Think back – the script for the lights also starts
when you press the “t” key. In this way, lights and barrier are synchronised: that
means they both start at the same time.
To lower the barrier, we will rotate the pole in stages by using a “repeat” block.
Experiment with the number of repeats and the angle of turn to move the barrier
just the right amount.
After a set time, 13 seconds, we raise the barrier using another repeat block.
The train has passed, all the cars are safe. Well done!
For an example of this project in its finished state, open
RPiScratch/Projects/level_crossing.
Over to you
TASK: As an extra feature for this program, create a train sprite that moves
across the screen when the barrier drops.
Lesson 1.7: Scratch games
LEARNING OBJECTIVE: In this exercise, you will learn some of the techniques
used for game programming by playing some Scratch games.
Some of the most fun that you can have with Scratch is through programming
games. You can make games about anything you like. We have included two
sample games for you to investigate, and there are plenty more games and other
examples of programs in the Scratch Projects folder.
The starting point for each new game is the theme or idea, and the aim of the
game. When you have an idea for a game, think about the “story” you want to tell
and the game’s characters, players, pieces etc. that you will need. These will be
the sprites.
You can find great images for sprites and backgrounds by importing them from
the Scratch Media folders or by searching on Google Images, saving and importing
into Scratch. If you want to get some idea of how to get started and what you
can do, have a look at some other people’s games. The best way to learn how
to program is to examine other people’s scripts to see how they made cool
things happen.
Finally, you will need backgrounds for your stage to create the rooms, levels and
scenes in your game, so that your characters have somewhere to move around in.
Notes:
Tip...
Don’t forget to
add sounds and
music, as this
greatly enhances
a game.