Page 13 - Scratch Programming Playground
P. 13

4
          shooting Hoops with Gravity                                               67
          Sketch Out the Design  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 68
          A . Make the Cat Jump and Fall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 69
                1 . Add the Gravity Code to the Cat Sprite . . . . . . . . . . . . . . . . . . . . .  . 69
                Explore: For All Sprites vs . For This Sprite Only . . . . . . . . . . . . . . . . . 71
                2 . Add the Ground Level Code  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 73
                3 . Add the Jumping Code to the Cat Sprite . . . . . . . . . . . . . . . . . . . .  . 74
          B . Make the Cat Move Left and Right . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 75
                4 . Add the Walking Code to the Cat Sprite  . . . . . . . . . . . . . . . . . . . .  . 76
          C . Make a Hovering Basketball Hoop  . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 77
                5 . Create the Hoop Sprite  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 77
                6 . Create the Hitbox Sprite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 79
          D . Make the Cat Shoot Hoops   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 81
                7 . Create the Basketball Sprite  . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 81
                8 . Add the Code for the Basketball Sprite  . . . . . . . . . . . . . . . . . . . . .  . 82
                9 . Detect Whether a Basket Is Made  . . . . . . . . . . . . . . . . . . . . . . . . .  . 83
                10 . Fix the Scoring Bug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 85
          The Complete Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 87
          Version 2 .0: Two-Player Mode  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 88
                Duplicate the Cat and Basketball Sprites  . . . . . . . . . . . . . . . . . . . . .  . 88
                Modify the Code for the Cat2 Sprite   . . . . . . . . . . . . . . . . . . . . . . . . .  . 89
                Modify the Code for the Basketball2 Sprite   . . . . . . . . . . . . . . . . . . .  . 90
          Cheat Mode: Freeze the Hoop   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 91
          Summary  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 92
          Review Questions  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 92


          5
          a Polished Brick Breaker Game                                             93

          Sketch Out the Design  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 94
          A . Make a Paddle That Moves Left and Right   . . . . . . . . . . . . . . . . . . . . . .  . 95
                1 . Create the Paddle Sprite   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 95
                Explore: Rotation Styles   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

          B . Make a Ball That Bounces Off the Walls  . . . . . . . . . . . . . . . . . . . . . . . .  . 98
                2 . Create the Tennis Ball Sprite . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 98
          C . Make the Ball Bounce Off the Paddle  . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 99
                3 . Add the Bounce Code to the Tennis Ball Sprite  . . . . . . . . . . . . . .  . 99
                Explore: Cloning   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
          D . Make Clones of the Brick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 102
                4 . Add the Brick Sprite  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 102
                5 . Clone the Brick Sprite   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 102




                                                                         COnTEnTS In DETAIL   xi
   8   9   10   11   12   13   14   15   16   17   18