Page 14 - Scratch Programming Playground
P. 14

E . Make the Ball Bounce Off Bricks   . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 104
              6 . Add the Bounce Code to the Brick Sprite   . . . . . . . . . . . . . . . . . .  . 104
        F . Make “You Win” and “Game Over” Messages . . . . . . . . . . . . . . . . . . . .  . 105
              7 . Modify the Tennis Ball Sprite’s Code . . . . . . . . . . . . . . . . . . . . . .  . 105
              8 . Create the Game Over Sprite . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 106
              9 . Create the You Win Sprite  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 107
        The Complete Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 108
        Version 2 .0: Polishing Time  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 109
              Draw a Cool Backdrop   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 110
              Add Music  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 111
              Make the Paddle Flash When Hit  . . . . . . . . . . . . . . . . . . . . . . . . . .  . 112
              Add an Animated Entrance and Exit to the Bricks   . . . . . . . . . . . .  . 112
              Add a Sound Effect to the Brick Exit . . . . . . . . . . . . . . . . . . . . . . . .  . 115
              Add a Sound Effect to the Tennis Ball . . . . . . . . . . . . . . . . . . . . . . .  . 117
              Add a Trail Behind the Tennis Ball . . . . . . . . . . . . . . . . . . . . . . . . .  . 117
              Add an Animated Entrance for the Game Over Sprite . . . . . . . . . .  . 119
              Add an Animated Entrance for the You Win Sprite  . . . . . . . . . . . .  . 120
        Summary  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 122
        Review Questions  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 123

        6
        snaaaaaake!                                                              125

        Sketch Out the Design  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 127
        A . Make a Snake Head That Moves Around  . . . . . . . . . . . . . . . . . . . . . . .  . 127
              1 . Create the Head Sprite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 128
              Explore: when key pressed vs . if key pressed? then  . . . . . . . . . . . . . . . 130
        B . Make Apples Appear   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 131
              2 . Add the Apple Sprite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 131
        C . Make a Body That Appears Behind the Snake Head . . . . . . . . . . . . . .  . 132
              3 . Create the Body Sprite  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 132
              4 . Create the Body Sprite’s Second Costume . . . . . . . . . . . . . . . . . .  . 133
              5 . Add the Code for the Body Sprite . . . . . . . . . . . . . . . . . . . . . . . . .  . 133
              6 . Detect Whether the Snake Crashes into Itself or a Wall  . . . . . .  . 135
        The Complete Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 137
        Version 2 .0: Add Bonus Fruit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 138
        Cheat Mode: Invincibility  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 140
              Modify the Head  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 140
              Modify the Body Code  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 141
        Cheat Mode: Chop Off Your Tail! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 142
        Summary  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 142
        Review Questions  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .  . 143





      xii    COnTEnTS In DETAIL
   9   10   11   12   13   14   15   16   17   18   19