Page 126 - Scratch Programming Playground
P. 126

You’ll use the broadcast message in script u to control
                         what happens when the ball touches the paddle in script v.
                             The point in direction 180 - direction code in script v
                         might seem a bit mysterious, but this simple equation cal-
                         culates the direction in which the ball will bounce based on
                         the ball’s current direction. If the ball is pointed up and right
                         (45 degrees), then when it bounces off the bottom of a brick,
                         its new direction will be down and right (135 degrees, because
                         180 – 45 = 135). If the ball is pointed up and left (−45 degrees),
                         then when it bounces off the bottom of a brick, its new direction
                         will be down and left (225 degrees, because 180 – (–45) = 225).

                                        Ball pointed               Ball pointed
                                        up and right                up and le








                                     180 – 45 = 135            180 – (–45) = 225


                             You’ll use this broadcast message again later in the pro-
                         gram when you add code to make the ball bounce off the
                         bricks.






      100   ChapTer 5
   121   122   123   124   125   126   127   128   129   130   131