Table of Contents
Acknowledgments xiv
Introduction xv
Who This Book Is For xvi
About This Book xvii
How to Use This Book xviii
Online Resources xix
Errata and Updates xix
1 Getting Started with Scratch 1
Running Scratch 3
Scratch Desktop: The Offline Editor 4
The Scratch Editor and Sprites 5
The Paint Editor 6
Working with Code Blocks 8
Adding Blocks 8
Deleting Blocks 10
Running Programs 10
Showing Off Your Programs 11
Getting Help 12
The Tutorials Window 12
The See Inside Button 12
Summary 13
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 21
Explore: Direction and Degrees 22
4 Duplicate the Dot 1 Sprite 24
C Draw the Rainbow Lines 25
5 Add the Code for the Drawing Dot Sprite 25
The Complete Program 28
Turbo Mode 29
Summary 30
Review Questions 31
3 Maze Runner 33
Sketch Out the Design 34
A Make the Cat Walk Around 36
Explore: X- and Y-coordinates 36
1 Add Movement Code to the Player Sprite 38
2 Duplicate the Movement Code for the Cat Sprite 39
B Make the Maze Levels 41
3 Download the Maze Images 41
4 Change the Backdrop 41
5 Start at the First Maze 41
C Keep the Cat from Walking Through Walls 42
6 Check Whether the Cat Is Touching the Walls 42
D Make a Goal at the End of the Maze 44
7 Create the Apple Sprite 45
8 Detect When the Player Reaches the Apple 45
9 Add the Broadcast Handling Code to the Maze Sprite 47
The Complete Program 47
Version 2.0: Two-Player Mode 49
Duplicate the Apple Sprite 49
Modify the Apple2 Sprite's Code 50
Duplicate the Orange Cat Sprite 50
Modify the Code for the Blue Cat Sprite 51
Go Back to the Starting Position 53
Cheat Mode: Walk Through Walls 54
Add the Walk-Through-Walls Code to Orange Cat 54
Add the Walk-Through-Walls Code to Blue Cat 54
Summary 55
Review Questions 56
4 Shooting Hoops with Gravity 57
Sketch Out the Design 58
A Make the Cat Jump and Fall 59
1 Add the Gravity Code to the Cat Sprite 59
Explore: For all sprites vs. For this sprite only 61
2 Add the Ground-Level Code 64
3 Add the Jumping Code to the Cat Sprite 65
B Make the Cat Move Left and Right 66
4 Add the Walking Code to the Cat Sprite 66
C Make a Hovering Basketball Hoop 67
5 Create the Hoop Sprite 67
6 Create the Hitbox Sprite 69
D Make the Cat Shoot Hoops 72
7 Create the Basketball Sprite 72
8 Add the Code for the Basketball Sprite 73
9 Detect Whether a Basket Is Made 75
10 Fix the Scoring Bug 77
The Complete Program 80
Cheat Mode: Freeze the Hoop 82
Summary 83
Review Questions 84
5 A Polished Brick Breaker Game 85
Sketch Out the Design 86
A Make a Paddle That Moves Left and Right 87
1 Create the Paddle Sprite 88
Explore: Rotation Styles 89
B Make a Ball That Bounces Off the Walls 90
2 Create the Tennis Ball Sprite 90
C Make the Ball Bounce Off the Paddle 91
3 Add the Bounce Code to the Tennis Ball Sprite 91
Explore: Cloning 93
D Make Clones of the Brick 94
4 Add the Brick Sprite 94
5 Clone the Brick Sprite 95
E Make the Ball Bounce Off Bricks 97
6 Add the Bounce Code to the Brick Sprite 97
F Make "You Win" and "Game Over" Messages 98
7 Modify the Tennis Ball Sprite's Code 98
8 Create the Game Over Sprite 98
9 Create the You Win Sprite 100
The Complete Program 101
Version 2.0: Polishing Time 102
Draw a Cool Backdrop 103
Add Music 104
Make the Paddle Flash When Hit 104
Add an Animated Entrance and Exit to the Bricks 105
Add a Sound Effect to the Brick Exit 108
Add a Sound Effect to the Tennis Ball 110
Add a Trail Behind the Tennis Ball 110
Add an Animated Entrance for the Game Over Sprite 112
Add an Animated Entrance for the You Win Sprite 113
Summary 115
Review Questions 117
6 Asteroid Breaker … In Space! 119
Sketch Out the Design 120
A Make a Spaceship That Is Pushed Around 122
1 Create the Spaceship Sprite 122
B Make the Spaceship Wrap Around the Edges 124
2 Add the Wrap-Around Code to the Spaceship Sprite 125
3 Add the Random-Push Code to the Spaceship Sprite 126
C Aim with the Mouse and Fire with the Spacebar 127
4 Create the Energy Blast Sprite 127
D Make Asteroids That Float Around 130
5 Create the Asteroid Sprite 131
E Make Asteroids Split in Two When Hit 133
6 Add the Asteroid's Splitting Code 133
7 Add the Asteroid Blasted Message Code to the Energy Blast Sprite 135
F Keep Score and Make a Timer 136
8 Create the Out of Time Sprite 136
G Make the Spaceship Explode If It Is Hit 138
9 Upload the Explosion Sprite 138
10 Add the Code for the Explosion Sprite 138
11 Add the Explode Code to the Spaceship Sprite 139
Version 2.0: Limited Ammo 141
Cheat Mode: Starburst Bomb 143
Summary 144
Review Questions 146
7 Making an Advanced Platformer 147
Sketch Out the Design 148
A Create Gravity, Falling, and Landing 150
1 Create the Ground Sprite 150
2 Add the Gravity and Landing Code 151
3 Make the Cat Walk and Wrap Around the Stage 153
4 Remove the Ground Lift Delay 155
B Handle Steep Slopes and Walls 157
5 Add the Steep Slope Code 157
C Make the Cat Jump High and Low 161
6 Add the Jumping Code 161
D Add Ceiling Detection 163
7 Add a Low Platform to the Ground Sprite 163
8 Add the Ceiling Detection Code 164
E Use a Hitbox for the Cat Sprite 167
9 Add a Hitbox Costume to the Cat Sprite 168
10 Add the Hitbox Code 169
F Add a Better Walking Animation 170
11 Add the New Costumes to the Cat Sprite 171
12 Create the Set Correct Costume Block 172
G Create the Level 179
13 Download and Add the Stage Backdrop 179
14 Create a Hitbox Costume for the Ground Sprite 180
15 Add the Ground Sprite's Code 181
16 Add More Wrap-Around Code to the Cat Sprite 182
H Add Crab Enemies and Apples 184
17 Add the Apple Sprite and Code 184
18 Create the Crab Sprite 185
19 Create the Enemy Artificial Intelligence 186
20 Add the Time's Up Sprite 191
Summary 192
Review Questions 193
Where to Go From Here 195
Index 197