Hardware Reference
In-Depth Information
FIGURE 3-17 Controlling the direction and movement of the Adventurer Sprite
Entering a Cave and Switching
Backgrounds
he action in a role-playing game typically involves the characters moving among dif-
ferent scenes. In this game, the Adventurer sprite begins outside a cave and has to
cross the stage to get to the cave entrance before going inside. At the start of this proj-
ect you were asked to create two backgrounds for the stage: one outside the cave that
you have been using so far, and one for the inside of the cave. But how do you get the
Adventurer sprite to switch between these backgrounds? You need a script for each of
the backgrounds, another script for the Adventurer sprite and another for the stage.
Adding a Script to Make the Adventurer Sprite Move
Between Backgrounds
Scratch programs are built up out of a collection of small scripts. Sometimes you need
a way to communicate among these scripts when certain things happen in your adven-
ture gameā€”for example, when you move the Adventurer sprite from one location or
background to another. his next script will use a new sprite to act as a trigger, so that
when the Adventurer sprite touches it, a message is broadcast to all the sprites and
the stage at the same time, to alert them to the change.
1. First, you need to create a new sprite to act as the cave entrance. Simply click the
Paint New Sprite button (the paintbrush icon) on the Sprites palette and use the
circle tool to draw an ellipse that matches the entrance of your cave (see Figure
3-18). his ellipse will be your new sprite.
2. Name the sprite portal and position it at your cave entrance on the opposite side
of the stage from where your Adventurer sprite starts. his new portal sprite will
act as the trigger to move between the two backgrounds.
3. Select the Adventurer sprite from the sprite palette and add another new script
to act as a thread on the Adventurer sprite Scripts tab. Add a when clicked
control block onto the Scripts tab of the Adventurer sprite, and add the wait
until _ block to it. his is another type of conditional block, but unlike with
the forever loop, the sequence of instructions happens only once when the
condition is true. In this case the condition will be true when the Adventurer
sprite 'touches' the portal sprite.
Search WWH ::




Custom Search