Cool Scratch Projects TOCCh1 1
Cool Scratch Projects TOCCh1 1
Introduction
Top tips for making these cool projects 7
Notes and Resources 8
1 Magic Mirror 9
Introducing Magic Mirror 10
Using Scratch 11
Using Scratch 1.4 12
Making the cat move 13
Making the mirror 16
Adding the reflection 19
Adding the magic controls 20
Polishing the magic mirror 22
2 Gribbet! 23
Introducing Gribbet! 24
Drawing the frog’s body 25
Drawing the frog’s face 28
Drawing the background 30
Animating the eyes 31
Setting up the variables 33
Adding the frogs’ scripts 34
Making the final images 37
Adding the main game script 38
Ending the game 39
Customizing Gribbet! 40
3 Drum Machine 41
Introducing Drum Machine 42
Drawing the background 43
Drawing the grid 44
Adding the beat marker 45
Adding the cursor 47
Adding the switch controls 49
Adding a drum 51
Adding finishing touches 53
Remixing Drum Machine 54
4 12 Angry Aliens 55
Introducing 12 Angry Aliens 56
How the 3D effect works 57
Testing the anaglyph effect 58
Making the starry sky 59
Drawing the crosshairs 60
Moving the crosshairs 62
Adding the target sprites 64
Adding the red alien scripts 65
Adding the cyan alien scripts 66
Adding the fire button 67
Customizing the game 68
5 3D Artist 69
Introducing 3D Artist 70
Building 3D Artist 71
Adding the random artist 73
Customizing 3D Artist 74
6 Space Mine 3D 75
Introducing Space Mine 3D 76
Drawing the tunnel 77
Drawing the numbers 78
Setting up the game 79
Adding the tunnel 80
Adding the numbers 81
Building the game 83
Adding the finishing touches 86
7 Maze Maker and Circuit Breaker 87
Introducing Maze Maker 88
Making the grid 89
Preparing the background 90
How the maze maker works 91
Checking rooms and walls 92
Understanding how it works 95
Testing the wall checker 96
Preparing for the cat code 97
Making the maze maker 98
Adding components 99
Saving mazes 100
Displaying mazes 101
Adding the bug 102
Adding the player’s sprite 104
More amazing ideas to try 107
Index
Introduction
This book shows you how to build lots of cool projects in Scratch.
My other book, Scratch Programming in easy steps, goes into
more depth on how Scratch works. Some readers might read that
book first and then come here to try these new projects. Others
will enjoy making these projects first and then seek out the
Scratch Programming book when they want to understand more If you share these
projects or reuse bits
about what the blocks do.
of them in your own
I recommend you start this book with Magic Mirror and Gribbet!, projects, please mention
because they gently introduce some ideas you’ll need for other this book. Thank you!
projects later. As you build these projects, think about what each
script does, so you avoid making mistakes copying from the book.
7
which computers and
work, so you need to hold the Shift key and click instead. Scratch versions the
l
project works on. 3D
3 Tweak for Raspberry Pi. Look out for special Artist doesn’t work on
instructions for the Raspberry Pi. Not all projects will the Raspberry Pi, for
work on the Pi, especially if you have an older model. example, and some
projects run slowly on
l
using Scratch 1.4, you’re
7 Take care with yellow brackets. It can get difficult when on a Raspberry Pi, and
you have brackets inside brackets, but the program won’t that if you’re using
work if you put blocks in the wrong place. Scratch 2.0, you’re using
it online.
Introduction
l
8
3 Type in /usr/share/scratch/timidityinstall.sh
Acknowledgements
Thank you to Sevanti and the team at In Easy Steps, David
Burder from 3D Images Ltd, Danny Wolfers, and Tim Rowledge.
Scratch is developed by the Lifelong Kindergarten Group at the
MIT Media Lab. See http://scratch.mit.edu
ScratchJr is a project of Tufts University, MIT Media Lab, and
Playful Invention Company. See http://scratchjr.org
Dedication
This book is dedicated to Karen and Leo. Leo loves the color
By the same author, green. We hope he will one day enjoy the inside of this book as
Scratch Programming much as the cover. Special thanks to Karen for all of her support.
in easy steps covers the
full range of Scratch’s About the author
capabilities, and has Sean McManus is an expert technology author. His previous
more detail on how the books include Scratch Programming in easy steps, Web Design in
language works. easy steps and Raspberry Pi For Dummies (co-authored).
1 Magic Mirror
• Stage: This is where you can see your animations and games
in action. When Scratch starts, there’s a large orange cat in
the middle of the Stage.
• Sprite
There’s also ScratchJr for
List: The cat is a ‘sprite’, which is like a character or tablet devices, covered
object in a game. The Sprite List shows all the sprites that are in Chapter 11. It’s
in your project. You click them to switch between them. completely different to
• Blocks
the computer versions of
Palette: In Scratch, you give the computer commands Scratch.
using blocks, which are instructions that fit together like
jigsaw pieces. The Blocks Palette presents you with all the
blocks you can use. When you start Scratch, you can see the
Motion blocks, which are color-coded in dark blue, and are
used for moving sprites. You can browse a different set of
blocks in the Blocks Palette by clicking one of the buttons
above it, such as the Looks button or the Sound button.
11
Scratch 2.0. It doesn’t
The screen is laid out differently in Scratch 1.4 (the older version,
work on the Raspberry
but still used on the Raspberry Pi) and Scratch 2.0 (the newer Pi or on the iPad, but
version). See below for the layout in Scratch 2.0, and see page 12 it runs on most other
for Scratch 1.4. computers.
Tabs
Scripts Area
Stage
Blocks Palette
Sprite List
• Scratch
Don’t get in a spin looking for rotation!
2.0 has a block called set rotation style. This block
doesn’t exist in Scratch 1.4. Instead, you look above the
Blocks Palette and click one of the three buttons to the left
of your sprite. The middle button sets the style to left-right.
Scratch 2.0 also has
new blocks for cloning
12
Tabs
Blocks Palette
Stage
Scripts Area
Sprite List
l
If you can’t find the
2 Click the Events or Control button above the Blocks exact block you need,
Palette. Find the block called when space key pressed. check for something
Drag it and drop it in the Scripts Area. similar with a menu in it.
It might have the option
(pictured, right).
13
Blocks Palette.
To get rid of a block
l
again, drag it back
5 Drag a point in into the Blocks Palette.
direction 90 block Careful, though: it will
into the Scripts take any attached blocks
Area. Drop it just underneath your previous block, so that with it!
it joins to the previous block. Joined blocks make up what
is called a “script”. A game is made up of lots of scripts.
l
In Scratch 2.0, if you
8 Drag a next costume create an account and
block and attach it log in before you start,
to the bottom of it will automatically
your script. Check save your work for you.
your script with the Click your name in the
top right to find your
picture here.
projects (or “stuff” as
the menu says).
Magic Mirror
...cont’d
l13 In Scratch 1.4, you need to set the rotation style to left-
right using a button beside the sprite above the Blocks
Palette. It’s the middle button with a double-headed
arrow on it. Click it to set the rotation style.
15
When you drag a block
out of a script, all the
blocks underneath go
with it. To remove just
one block, first drag it
out, with the attached
blocks. Then drag the
attached blocks away
and back into the script.
To delete the spare
l14 Add the script below to make the cat jump when you
press the up arrow key.
blocks, drag them back
into the Blocks Palette.
l
the images at the back
of the Stage. Sprites 2 In Scratch 2.0, click the Indoors category on the left.
cannot go behind them. In Scratch 1.4, double-click the Indoors folder. You can
scroll to see more pictures here. Find a picture you like,
click it and then click OK.
16
l 6 The tools are to the left of the canvas area. Click the Fill
tool. Click the canvas to fill it with your chosen color.
17
selected in the toolbox.
The Rectangle is to its
right. The Paintbrush is
on the left end of that
row of tools.
...cont’d
l 8 Pick a color for the carpet and use the Rectangle tool to
draw it. To draw a rectangle, click in the top left corner of
your shape, hold down the mouse button and drag to the
bottom right. Refer to the picture on page 17 to get an
idea of how big to make it, and where to put the mirror
Always make sure you’re and buttons later.
adding your scripts to
the right sprite. Click the
sprite in the Sprite List
before adding a script to
be sure.
l 9 We need to change how thick the mirror’s frame is, by
changing the size of the brush used to draw it. In Scratch
2.0, move the slider underneath the Fill options to the
right to make the line thicker. In Scratch 1.4, click the
Paintbrush tool, then click the brush size menu under the
tools to change the line width. Click the Rectangle tool
and select the hollow rectangle option. Pick the frame
color for your mirror in the color palette and draw the
mirror’s frame on the canvas.
l10
18
l
Below: Your images in
place. The background 12 In Scratch 1.4, click the OK
shows through the button. In either version,
transparent ink in the click the Scripts tab and
mirror. add the script on the right
to the mirror sprite.
19
could get confusing so let’s rename one of them. In
Scratch 2.0, click the i button on the sprite in the Sprite
List and the sprite’s name is shown at the top of the
information pane that opens. In Scratch 1.4, click the
sprite in the Sprite List and its name is shown in a dark
box above the Scripts Area. In either case, click the name
to edit it, and change the new sprite’s name to “reflection”.
In Scratch 2.0, click the back button (right)
in the top left of the information pane to go
back when you’ve finished.
l 3 Click the Scripts tab and find the script that starts with
when green flag clicked. Add the rest of the blocks
shown in this script, starting with the forever block.
Inside the forever block is an if block (not an if... else
block). Inside the if block are the broadcast and play
sound blocks. Take care to get the right blocks inside
the right brackets. For the touching color Sensing block,
click the color in it and then click one of the buttons
20
l 4 If you’re using
Scratch 2.0
online, hold
down the Shift If the buttons are too
key and click the high for the cat to
if block in your reach, the easiest fix
script. If you’re is to edit the wall and
using Scratch 1.4 mirror image to move
the buttons down.
or Scratch 2.0
Alternatively, you can
offline, right- change the starting y
click the block. position in the go to x:
When the menu y: block in the when
appears, click green flag clicked
duplicate. Drop scripts on the cat and
your duplicated reflection sprites. Make
script underneath it a higher number (for
your if block example -100 instead of
but inside the -120) to move the cat up.
21
forever bracket. Change the touching color block and the
broadcast message for another button, and repeat to set
up all three buttons.
You can share your The best way to use this book is not just to make the projects, but
projects on the Scratch also see if you can find ways to adapt them, personalize them and
website so people all improve them. Start by reading the scripts to see if you can work
over the world can enjoy out what they do, and how they work together.
them. Please give credit
to this book if you’re Here are some suggestions for changes you could make:
sharing or adapting its
projects. Thank you! • Get arty. Give the reflection a hat or change its color by
editing the costume for the reflection sprite. You could also
edit the costume for the wall and mirror sprite to draw some
furniture in the room, or a tasteful portrait on the wall.
Make sure you save your sometimes. Perhaps you could add a reset button too, to turn
work frequently so you the mirror’s distortion off ?
don’t lose it. Scratch 2.0
online will save work for • More exercise. The jump control uses a repeat 10 block to
move the cat up in small steps, and then move it back down
you automatically from
time to time. In Scratch again. It’s a simple but effective animation. Try experimenting
1.4, use the File menu. with the numbers in this script. Can you make the cat jump
higher, or faster? Can you make the cat furiously kick its legs
as it falls through the air after a jump? You’ll need a next
costume block but you’ll have to figure out where to put it.
You could add different key controls for different styles of
Below: The color effect jumps.
can turn the cat green.
• More rooms. Could you add additional rooms with magic
mirrors in? Design the different room walls as costumes in
the wall and mirror sprite. Use the if block to detect when
the cat’s x position is more than 230 (leaving on the right),
and then change its x position to be on the left (-230 which
would be the position arriving on the left). Use a broadcast
to get the mirror to change to the next costume too. Can you
enable the cat to walk to rooms on the left too? That’s a lot
harder, because there’s no previous costume block.