Page 52 - Learn To Program With Scratch
P. 52

try it out 2-2
                            Find the rocket’s final (x,y) position when it executes each of the two scripts shown
                            below . What mathematical theorem can you use to prove that the two scripts are
                            equivalent?

                                                                           y
                                                                      100
                                         
                                                                        50

                                                                                       x
                                                                              50  100
                                                                         



                         Other Motion Commands
          TennisBallChaser   There are just four motion commands left to explore: point towards; a sec-
                     .sb2  ond type of go to block; if on edge, bounce; and set rotation style.
                             You’ve already learned about rotation styles, and you saw the if on edge,
                         bounce command in action in Chapter 1 (see Figure 1-13 on page 12). To
                         see the other two commands in action, let’s create a simple application of
                         a cat chasing a tennis ball, as illustrated in Figure 2-8.

                                                     Script for the Ball sprite






                                 Script for the Cat sprite


                         .
                         Figure 2-8: Programming a cat to run after a tennis ball

                             As shown, the application contains two sprites, named Cat and Ball,
                         and two scripts. When you click the green flag icon, the Ball sprite follows
                         the mouse pointer. The Cat sprite continuously points towards the Ball and
                         moves toward it using the glide command. Go ahead and build this appli-
                         cation to see how it works. You can find the forever block in the Control
                         palette and the mouse x and mouse y blocks in the Sensing palette. You
                         can find the complete application in the file TennisBallChaser.sb2.
                             In the next section, we’ll look at the Pen palette and learn how to make
                         a sprite leave a visual trace of its motion.








           30   Chapter 2
                                           www.it-ebooks.info
   47   48   49   50   51   52   53   54   55   56   57