Raspberry_Pi_Education_Manual

We need some script to make the bee look as if it is flying. We do this by switching from one costume to another and back again, making the bee appear to flap its wings. As we do this we will also make the bee move forwards. Now, build your own script to make the bee fly. You will need blocks from Control, Looks and Motion. If you get stuck, have a look at the screenshot of our code. You’ll find it further on in the lesson.

Notes:

This is the code to make your bee fly. Instead of using the green flag to run my code, I will use a “when Sprite1 clicked” block from Control. The code will run when I click on the bee.

Here are the steps you need to follow:

1.  Start with costume “ bee1 ”. 2.  Add a “wait [0.2] secs” block, so that the viewer has time to see the costume. 3.  Move the bee on 10 steps, before switching to costume “ bee2 ”. 4.  Add another “wait [0.2] secs” block, so that the viewer has time to see the second costume. 5.  Move the bee on another 10 steps.

But we need to do this more than once. To make the bee fly across the screen, we might have to repeat this 20 times.

Don’t panic! You are using a computer. Computers are fantastic at doing things over and over again. They can do this very accurately and never get bored, tired or fed up.

What we need is a repeat loop.

This is what we use to program the computer to repeat something over and over again. You will find the repeat loop (“repeat [10]”) in the Control blocks.

A beginner’s guide to Scratch

19

Made with FlippingBook flipbook maker