Hardware Reference
In-Depth Information
FIGURE 3-23 An if else script is used to show and hide sprites in Scratch.
Creating Health-Point-Stealing
Sprites
he Adventurer sprite can now move around the stage and move between stage back-
grounds using the broadcast message. However, as it stands, this will be a really easy
game to play and anyone playing the game may tire of it very quickly! You can make
the journey to the cave entrance more diicult for the player by adding obstacles that
will steal health points.
1. To add some obstacles to make it more diicult for the Adventurer sprite to get
around the stage, click the Paint New Sprite icon to create a new sprite. Use the
tools to draw a flower as your new sprite, and name it flower .
2. Next, add a script to the flower sprite by selecting it from the Sprites panel and
then dragging the control block when
clicked onto the Scripts tab.
3. he obstacle needs to be a constant danger for the sprite, so you need a script
that is constantly running. To achieve that, add the forever if block. his
time the condition will be if the Adventurer sprite is touching the flower then remove
a certain number of health points . Add the sensing block touching _ . Figure
3-24 shows the completed block.
4. Inside the forever if block, add the variable block change health by 0
and change the value from 0 to -10 so that it removes health points from the
player.
5. Add the looks block say ouch! for 2 secs after the variable block inside the
forever if loop block.
6. Remember to add the if else script to hide the flower sprite after the player
enters the cave, and then save and test your script.
Search WWH ::




Custom Search