Hardware Reference
In-Depth Information
Figure 11-10:
The completed
code for the
simple Scratch
game's cat sprite
If you move the cat towards the Cheesy-Puffs with the right-arrow key on the keyboard, the
game starts. When the cat reaches the Cheesy-Puffs, the dialogue exchange takes place and
the bowl should disappear.
Although this example is effective for introducing some important programming concepts,
it's hardly the best way the game could be coded. Scratch includes a message broadcast system
that allows code attached to one object to communicate with code attached to another,
which enables you to create much neater collision results that don't rely on carefully timed
pauses in order to make sense.
To experiment with broadcasting, try using the broadcast and when I receive blocks
from the Control palette. A message created for a broadcast block in any object can trigger
code in any other object using the when I receive flag, meaning you can use it to link
multiple objects and their code together.
Search WWH ::




Custom Search