Raspberry_Pi_Education_Manual

Notes:

2. Random changes in direction

If the pony never changes direction except when it hits an edge, the game will get a bit dull. So we’ll use another “forever” loop to make the pony randomly change direction from time to time.

The “pick random [ ] to [ ]” Operator block has been set to pick a random number from 1 to 4. If the number picked is 1, the pony will turn 180 degrees.

This is set to happen every 0.5 seconds by the “wait” block.

3. Move the girl with your mouse pointer

Select the girl sprite in the Sprites List. Using yet another “forever” loop, as well as blocks from Motion and Sensing:

n  Set the x coordinate of the girl sprite to the x position of the mouse pointer. n  Set the y coordinate of the girl sprite to the y position of the mouse pointer.

4. Score a point each time the girl is placed on the pony.

In this script, you can see the following:

n  We have created a variable to handle the score and named it “score” (imaginatively!). n  When the game starts the score is set to “0”. n  The “forever if” loop checks to see if the red colour of the girl’s top is touching a small blue dot on the saddle of the pony. n  Every time the red touches the blue the score is changed to “score + 1”.

A beginner’s guide to Scratch

46

Made with FlippingBook flipbook maker