Table of Contents
Acknowledgments xvii
Introduction xix
Who This Book Is For xx
About This Book xxi
How to Use This Book xxii
Online Resources xxiii
Errata and Updates xxiii
1 Getting Started with Scratch 1
Running Scratch 3
The Offline Editor 4
The Scratch Editor and Sprites 4
The Paint Editor 6
Working with Code Blocks 8
Adding Blocks 8
Deleting Blocks 9
Running Programs 10
Showing Off Your Programs 11
Getting Help 11
The Tips Window 12
The See Inside Button 13
Summary 14
2 Rainbow Lines in Space! 15
Sketch Out the Design 16
A Create the Space Backdrop 18
1 Clean Up and Set the Stage 18
B Create Three Bouncing Dots 20
2 Paint the Dot 20
3 Add Code for the Dot 1 Sprite 22
Explore: Directions and Degrees 23
4 Duplicate the Dot 1 Sprite 25
C Draw the Rainbow Lines 25
5 Add the Code for the Drawing Dot Sprite 25
The Complete Program 28
Turbo Mode 28
Version 2.0: Rainbow Triangles 29
Version 3.0: Two Rainbow Lines 30
Version 4.0: You Decide! 31
Summary 32
Review Questions 33
3 Maze Runner 35
Sketch Out the Design 36
A Make the Cat Walk Around 38
Explore: X- and Y- Coordinates 38
1 Add Movement Code to the Player Sprite 40
2 Duplicate the Movement Code for the Cat Sprite 41
B Make the Maze Levels 43
3 Download the Maze Images 43
4 Change the Backdrop 43
5 Start at the First Maze 43
C Keep the Cat from Walking Through Walls 44
6 Check Whether the Cat Is Touching the Walls 44
D Make a Goal at the End of the Maze 46
7 Create the Apple Sprite 47
8 Detect When the Player Reaches the Apple 47
9 Add the Broadcast Handling Code to the Maze Sprite 49
The Complete Program 49
Version 2.0: Two-Player Mode 51
Duplicate the Apple Sprite 51
Modify the Apple2 Sprite's Code 52
Duplicate the Orange Cat Sprite 52
Modify the Code for the Blue Cat Sprite 53
Go Back to the Starting Position 55
Version 3.0: Traps 56
Draw a New Sprite for the Traps 56
Create a Second Costume for the Traps 57
Add Cloning Code for the Traps 58
Modify the Orange Cat Code 59
Copy the Code from Orange Cat to Blue Cat 61
Cheat Mode: Walk Through Walls 62
Add the Walk-Through-Walls Code to Orange Cat 63
Add the Walk-Through-Walls Code to Blue Cat 63
Summary 64
Review Questions 65
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 Bail Sprite 99
Explore: Cloning 101
D Make Clones of the Brick 102
4 Add the Brick Sprite 102
5 Clone the Brick Sprite 102
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 us. 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
7 Fruit Slicer 145
Sketch Out the Design 147
A Make the Start Screen Backdrop 148
1 Draw the Backdrops 148
2 Add the Code for the Stage 150
B Make the Slice Trail 151
3 Draw the Slice Sprite 151
Explore: Making Lists 152
4 Create Lists and Variables for the Slice Sprite 155
5 Record the Mouse Movements 156
6 Make a Custom Block to Draw the Slice 157
C Make the Begin Button 160
7 Create the Begin Button Sprite 160
D Make the Fruit and Bombs Throw Themselves 162
8 Create the Fruit Sprite 163
9 Make the Sliced Fruit Costumes 164
10 Add the Code to the Fruit Sprite 167
11 Add the Code for the Fruit Sprite's Clones 170
E Make the Health Sprites 173
12 Create the Health Sprite 173
F Make the Game's Ending 176
13 Create the White Fade Out Sprite 176
Version 2.0: High Score 179
Cheat Mode: Recover Health 180
Summary 181
Review Questions 182
8 Asteroid Breaker… in Space! 183
Sketch Out the Design 184
A Make a Spaceship That Is Pushed Around 186
1 Create the Spaceship Sprite 186
B Make the Spaceship Wrap Around the Edges 188
2 Add the Wrap-Around Code to the Spaceship Sprite 188
3 Add the Random-Push Code to the Spaceship Sprite 190
C Aim with the Mouse and Fire with the Spacebar 190
4 Create the Energy Blast Sprite 191
D Make Asteroids That Float Around 194
5 Create the Asteroid Sprite 194
E Make Asteroids Split in Two When Hit 196
6 Add the Asteroid's Splitting Code 196
7 Add the Asteroid Blasted Message Code to the Energy Blast Sprite 198
F Keep Score and Make a Timer 199
8 Create the Out of Time Sprite 199
G Make the Spaceship Explode If It Is Hit 200
9 Upload the Explosion Sprite 201
10 Add the Code for the Explosion Sprite 201
11 Add the Explode Code to the Spaceship Sprite 202
Version 2.0: Limited Ammo 204
Cheat Mode: Starburst Bomb 206
Summary 207
Review Questions 208
9 Making an Advanced Platform 209
Sketch Out the Design 210
A Create Gravity, Falling, and Landing 212
1 Create the Ground Sprite 212
2 Add the Gravity and Landing Code 213
3 Make the Cat Walk and Wrap Around the Stage 215
4 Remove the Ground Lift Delay 216
B Handle Steep Slopes and Walls 218
5 Add the Steep Slope Code 218
C Make the Cat Jump High and Low 222
6 Add the Jumping Code 222
D Add Ceiling Detection 224
7 Add a Low Platform to the Ground Sprite 224
8 Add the Ceiling Detection Code 225
E Use a Hitbox for the Cat Sprite 228
9 Add a Hitbox Costume to the Cat Sprite 229
10 Add the Hitbox Code 230
F Add a Better Walking Animation 231
11 Add the New Costumes to the Cat Sprite 232
12 Create the Set Correct Costume Block 233
G Create the Level 239
13 Download and Add the Stage Backdrop 239
14 Create a Hitbox Costume for the Ground Sprite 240
15 Add the Ground Sprite's Code 241
16 Add More Wrap-Around Code to the Cat Sprite 242
H Add Crab Enemies and Apples 243
17 Add the Apple Sprite and Code 244
18 Create the Crab Sprite 245
19 Create the Enemy Artificial Intelligence 246
20 Add the Time's Up Sprite 250
Summary 252
Review Questions 253
Where to Go From Here 255
Index 257