The_Official_Raspberry_Pi_-_Beginner’s_Book_Vol1,_2018 (1)

(singke) #1
Chapter 4 Programming with Scratch^89

THE OFFICIAL RASPBERRY PI BEGINNER’S GUIDE


when clicked
broadcast new arrow

whenIreceive new arrow
gotox: -150 y: -150
setsizeto^400 %
forever
glide pickrandom -150to^150 y: pickrandom -150 to^150

when space keypressed
stop other scripts in sprite

0.5secstox:

If you’d stopped your program to add the new blocks, click the green flag to start it again
and then press the SPACE key: you’ll see the arrow sprite stop moving. That’s a start, but you
need to make it look like the arrow is flying to the target. Add a repeat 50 block followed by
a change size by -10 block, then click the green flag to test your game again. This time, the
arrow appears to be flying away from you and towards the target.


when clicked
broadcast new arrow

whenIreceive new arrow
gotox: -150y: -150
setsizeto 400 %
forever
glide pickrandom -150to 150 y: pickrandom -150 to 150

when space keypressed
stop other scripts in sprite
repeat^50
changesizeby -10

0.5secstox:

To make the game fun, you need to add a way to keep score. Still in the same stack of
blocks, add an if then block, making sure it’s below the repeat 50 block and not inside it, with a

Free download pdf