Game Development Reference
In-Depth Information
Prepare for lift off
If we haven't left it on the stage from the start, we have to add the Scratch cat as a new
sprite as shown in the following steps:
1.
Click on the
Choose
sprite from the library icon.
2.
Search for the
Scratch cat
opion, select it, and click on
OK
.
The Scratch cat will be loaded for use in the game. Next, we will add a script to it to make it
interacively controlled by the player.
Engage thrusters
Let's irst set up the broadcasts that will trigger the cat sprite to take proper acions. We
need two of those events. The first one is very simple and will be repeated in all game
objects as follows:
1.
Start a new script with
when I receive <createMaze>
.
2.
To this, add the
hide
block to hide the sprite as shown in the following screenshot:
This makes sure all other sprites are hidden when the
ileGenerator
sprite runs.
They will remain hidden unil we call them to do something later. The cat sprite will
be acivated right ater the maze is created.
3. Create a second broadcast script with
when I receive <startGame>
.
4. After this, we will place a
funcion
block. So now is a good ime to introduce
funcions.
With a funcion, you can describe a certain operaion that is repeated many imes
during the program. Instead of describing the steps required each ime they are
needed, just point to the funcion and tell the computer to perform those acions.
Using a funcion can save space in the running program, because we set speciic
sets of acions aside as separate scripts. This will also make the general low of the
program easier to understand.
5.
Click on the
More Blocks
category. This is where we can deine and use funcions.