Scratch 2
Scratch 2
This is an excerpt of
S u pe r
S c r atc h
e!
a Adventur
m m in g
Pr o g r
Learn to
by
Pr o g r a m
ool
Making C
Gam es!
The Project
10
N o te The Resources file includes two versions of each game
in the book. One version is a completely finished and
playable game, perfect for young learners and anyone
who wants to build on the games in the book. The
second set of projects has no programming added, so
that students can follow along with the programming
instructions in this book. Remember, theres no wrong
way to play with Scratch!
11
Who Created Scratch?
Scratch is a project funded by the US National Science Founda-
tion (NSF). It was developed by the Massachusetts Institute of
Technology (MIT) Media Labs Lifelong Kindergarten Group.
12
Designing Scratch projects challenges kids to think cre-
atively, and learning how to overcome obstacles and solve
problems builds confidence. This gives learners an advantage
later in life.
13
Scratch is used around the world in elementary, middle, and
high schools. Computer science professors also use Scratch as a
means of introducing programming concepts to college students.
14
Students at a university in Istanbul used Scratch to examine
video game culture by rapidly prototyping their own games
and testing the games with the public.
English students in a middle school in California used
Scratch to build a random story generator.
Students in an elementary school in Russia used Scratch to
build their own personalized tutorials for learning about the
coordinate system and trigonometry.
High school students in Michigan used Scratch to build a
physics simulator.
The possibilities are endless. It is our sincere hope that
thisbook inspires students to create their own games, stories,
and more.
15
or students know to keep their personal information
private.
16
My Computer Cant Run
Scratch 2!
If your computer doesnt meet the requirements listed on
page10, you can still downloadand installScratch 1.4. (http://
scratch.mit.edu/scratch_1.4/). Scratch 1.4 projects are compat-
ible with the Web-based Scratch 2, and you can still share your
projects on the Scratch website using Scratch 1.4. (Unfortunately,
Scratch 1.4 cannot read programs created in the Scratch 2
software.)
You can download free PDF versions of Chapters 1 and 2,
which explain how the older 1.4 interface works, by visiting
http://nostarch.com/scratch/. You can also find versions of the
books games that are compatible with 1.4 on that page.
17
Meet the Cast
Mitch
A computer science
student who loves to
make cool programs,
hes passionate about
movies and art, too!
Mitch is an all-around
good guy.
Beoo
Beoo o-
oo
p!
Earthqu
I sure wish ak
Meanwhile, in
programming e!
school on Earth...
were easier...
Whoa!
Chirp Chirp
Wake up.
W-who are
Come on, you? What just
wake up! happened?
My name is Thats right. I Amazing! My
Scratchy. followed that nameis Mitch. Im a
Im from flash of light, And computer science
Cyberspace. here I am! student!
Youre from a
computer?!
Oh no! I
cant move
my legs!
Hey Mitch.
umis your Where is
planet always
so gray?
everybody?
Ahhh!
Meneither!
Something Help!!
terrible is
forming in
the sky!
No way!
Somethings
wrong. Lets
go check
itout!
take this
Secret Manual
Stay Calm! beforethe
Thank goodness Black Tornado
Ifound you! swallows you!
Then follow my
Your body is instructions!
being frozen!
Lets
do
this!
Breaking the Spell!
Chapter Focus The Game
Lets get to know Scratch! We need to get Scratchy the cat
Well also learn about sprites moving again. Well make him
and coordinates. dance across the Stage.
an d D r
ck a
i
Cl
22
A Guided Tour of the Scratch Interface!
Palette
Sprite Toolbar Each of these ten buttons lets you choose
Contains the functions (called blocks) for programming your
Play the Give your Duplicate, Delete, sprites. You can combine these command
game full project a Grow, Shrink, and blocks in stacks to create programs that
screen. new name. Block Help tools control objects on the screen.
Stage
Displays your creation
Scripts Area
Heres where you build your
programs. Stacking blocks
The green flag starts the together here lets you control
game and the red flag the sprites in your project. Click
stops the game. one of the three tabs at the top
to change to other functions:
Scripts: Allows you to
drag command blocks from
the Palette and put them
together to write a program
Costumes: Allows you to
draw, import, or edit images
Sprite List
for a sprite
Here are the characters
and objects youve created, Sounds: Allows you to record
including the Stage itself. or import sound files for a
Click the icons to edit each sprite to use
sprite individually.
23
Sprite Information
You might have noticed a little blue i in the corner of the box around
Scratchy when you select his sprite in the Sprite List. Try clicking the i,
and youll get information about that sprite.
This section shows the sprites name, position, and direction it is facing
(the little blue line).
Choose
the xy-grid
backdrop and
click OK to
use it. Its in
the Other
category.
24
Now you can see exactly how Scratch positions objects.
Everything is on a grid with two axes:
y-axis: A vertical line that marks up and down positions;
ranges from 180 (lowest) to +180 (highest)
x-axis: A horizontal line that marks left and right positions;
ranges from 240 (farthest left) to +240 (farthest right)
Scratchys default position is at the point where the x-axis
and y-axis meet. Hiscoordinates are (X: 0, Y: 0).
25
Click the number of a coordinate to change it. Set x to 0 and
set y to 125. Now click the block to run it! Scratch goes right
tothat position. Weve just written our first program! Its really
that simple.
26
Type these coordinates in your
own program, so it matches this
picture. When youre finished,
click the whole command block
to make Scratchy jump around
in a pentagon shape!
27
Because we used the When clicked command, we
can use these buttons above the Stage to start ( )
and stop ( ) the game.
28
This software bug can be fixed by adding
some more codethat is, new blocksto
your program. In this case, simply place
a new go to block (from the blue Motion
palette) above the green Pen blocks and
below the When clicked block.
29
Remember to save
this file so you can
play with it later!
If you are logged into Scratch, the website stores all of your projects into
My Stuff so you can easily find them. The website saves your progress
every so often, but you can save manually too: File4Save Now. You can
also save different versions of your programs to make sure you dont lose
older versions of your games and can safely experimentFile4Save Copy
creates a new version of your project in My Stuff. If you want to download
a version for yourself, try File4Download to your computer. Then save
it in a safe spot!
Scratchys Challenge!!
Can you edit this program to make Scratchy draw
different kinds of shapes? Give it a try!
30
Entering
Space
Magic Alright! I can
star web! feel my limbs
sh again!
WhoO
32
Great Idea!
This Secret Yes! If I learn You can design
Manual saved to program, it new equipment and
us. Maybe might help to even control our
it can help defeat the Dark movements!
other people Wizard!
as well!
We need the
energy from seven
Alright! dimensional strings
But why does
to open the stargate
Scratchy need
the space suit?
and reach my
friends...
Oh no!
My fellow ...but inside the
defenders are in vortex, theres no
trouble! Change oxygen, and lightning
into a space suit can make things
and savethem, disappear!
kind feline!
by the way,
Gobo, my name
is Scratchy, and
hes Mitch! The adventure into
space begins
33
A Space Odyssey!
Chapter Focus The Game
Learn to design new costumes Avoid the lightning bolts and
and program a sprites move collect seven dimensional strings.
ments, reactions, and sound Once youve got them all, the
effects. Monolith will appear!
34
Heres where all the tools
are. The Brush and Eraser
tools make it easy to draw.
35
You also have tools to draw rectangles and ellipses.
Can you give Scratchy a stovepipe hat like Abe
Lincoln using the Rectangle and Ellipse tools?
36
To use the Select tool, use your
mouse to create a frame around a
certain area. Then you can do all
sorts of things to the selected part
of your costume:
Click and drag the selection to
move it to a new location.
Resize, smush, or stretch the
image using the handles on the
sides of the box
Rotate the selection by clicking
and dragging the handle at the
top center of the box
Press and hold the ctrl key and
C key at the same time to copy
the image area (Mac users can
use -C instead). Then press
ctrl-V to paste your selection,
as many times as youlike.
Press the delete key to erase
the selection.
37
Vector Mode
You may have noticed that
when you edit other sprites in
Scratch, you dont seethe same
Paint Editor tools. Some newer
sprites are vector artthats just
a fancy way to say theyre made
of shapes, instead of pixels.
Vector art have small filesizes,
but they are great qualityand
they can be resized without
losing quality.
38
Try opening a vector
graphic from Scratchs
library, and give editing
one a try.
The Backpack
Heres a cool new feature. If youre logged into the
Scratch website, youll see something called the
Backpack at the very bottom of the screen. Click it,
and itll open up. Yours will be empty until you throw
some sprites in it.
39
Once you know how to use the Paint Editors
tools, Scratchy can put on his space suit!
Goahead and draw your own, or use the
costume thats already in the project.
40
Next, lets take a look at the other
sprites in the game. You can use the
art thats already in the game, or
draw new artwork yourself! Click
to draw a new sprite.
41
Next, lets look at the Stage.
Iused artwork of a black hole
from NASA! You can draw a
new backdrop if you like. Click
the Stage in the Sprite List, and
then click the Backdrops tab.
42
For program , well make a conditionalif something
is true, then something else will happen. In the Control
palette, drag out an if block. Then for the diamond shape,
drag the Sensing block key ______ pressed?. Right below
the if, put what you want to happenwhen the statement
is true. Drag out the rest of these commands to form the
complete program. Now you can move Scratchy up, down,
left, and right by using the keyboard!
43
Now we can add sound effects to the game!
Ive already added a few, but you can change
things up. First, click the Stage in the Sprite
List. Then click its Sounds tab. You can create
whatever kind of sounds effects or music you
like for your Scratch projects. You can even
record your own sounds right in the Scratch
program.
If you click the Record button, a sound recorder will pop up.
You can click the round button to record speech or sound
effects through a microphone. When youre finished, click OK.
If you want to use sounds that are prerecorded, you can press
to use Scratchs sound library, or to choose files from
your own computer (MP3 and compressed WAV, AIF, and AU
formats are supported).
44
Now we can add some simple programs to the
Stage. Program makes its backdrop change
colors. Inprogram , use the Sound palette
toadd a song to the Stage.
45
The Lightning sprite needs some more
programs. Go to the Control, Events,
Looks, and Operators palettes and
program these commands to have the
lightning bolt randomly grow bigger
or smaller, making the game more
magical.
46
Now its time to program the String sprite.
Make sure you click it in the Sprite List first!
Program makes it change color, just like
our Stage. Program will give it a simple
animation, using the fisheye effect.
47
Then add to your program so that
it looks like . This will make your
dimensional string appear in a
random place on the Stage seven
different times. The say blocks
and play sound blocks at the end
of the program make sure the
player knows he has grabbed a
dimensional string.
48
Add a When clicked block at the top of our script
and some instructions at the very bottom so that once
Scratchy has collected seven dimensional strings, the
String sprite will change to its Monolith costume. When
that happens, the player wins the game. Make sure
your finished program looks like .
49
After saving the file, you can enjoy your final
creation! Make the Stage full screen and
click to begin a new round.
Scratchys Challenge!!
Add more lightning bolts to give yourself a
challenge. Or you could replace the lightning
bolt with a big, scary space monster you drew
yourself! Give it a try!
50
The adventure continues...
Get the gem and escape the battle the dark wizard in
booby-trapped maze! the awesome fighting
anawesome fighting game!
game!