Page 64 - Learn To Program With Scratch
P. 64

cart. If the clone detects that it is touching the cart w, that means it was
                         caught. Therefore, it increases the score, plays a sound, and deletes itself
                         (because it has no more work to do). If the clone falls below the cart x,
                         then the player missed; in this case, the clone plays a different sound
                         before deleting itself. If the clone is neither caught nor missed, then it’s
                         still falling, and the forever block goes around again.
                             Now that our apples know how to fall, the game is complete! Go ahead
                         and test it out by clicking the green flag. If you want to experiment, try
                         changing the wait time between cloning the different apples and the speed
                         of moving the cart. Does that give you some ideas for changing the game’s
                         difficulty?



              more on cloned Sprites
                         Any sprite can copy itself or another sprite using the create clone of block.
                         (The Stage can also clone sprites using the same block.) A cloned sprite
                         inherits the original’s state at the time it is cloned—that is, the original’s
                         current position and direction, costume, visibility status, pen color, pen
                         size, graphic effects, and so on. This idea is illustrated in Figure 2-25.

                                               At this point, the master sprite is
                                               at (−100,0), pointing right, and its
                                               size is set to 60%.
                                               The position, direction,        Master
                                               and size of the clone will
                                               be identical to those of the
                                               master.
                                               The master sprite changes its
                                               position and direction, and    Clone
                                               returns to its original size.

                         Figure 2-25: A clone inherits the attributes of its master .

                             Clones also inherit the scripts of the master sprite, as shown in Fig-
                         ure 2-26. Here, the master sprite creates two clones. When you press the
                         spacebar, all three sprites (the master and the two clones) turn 15° to the
                         right because they all execute the when space key pressed script.










                                                   Clone1  Clone2  Master
                         Figure 2-26: Clones inherit the scripts of their master .








           42   Chapter 2
                                           www.it-ebooks.info
   59   60   61   62   63   64   65   66   67   68   69