Book Image

Scratch 2.0 Beginner's Guide: Second Edition

By : Michael Badger
Book Image

Scratch 2.0 Beginner's Guide: Second Edition

By: Michael Badger

Overview of this book

Table of Contents (18 chapters)
Scratch 2.0 Beginner's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Finding a project for you


This book will give you a well-rounded introduction to Scratch. It's true that creating games are incredibly popular, and young boys tend to want to create games. However, there are other uses of Scratch, and plenty of people who want to do something other than just create games. Generally speaking, we'll make an animation, tell a story, build a game, create art, and sense the real world.

Making animations

An animation lets the sprites interact with each other. We'll use the common example of a birthday card to demonstrate animations. The following screenshot shows a birthday card example from Chapter 3, Creaing an Animated Birthday Card:

However, some folks have created more complicated projects using stop-motion animations. You can find some stop-motion animations on the Scratch website at http://scratch.mit.edu/studios/254628/.

Telling stories

The first story project we do will create a slideshow that's designed to be narrated with Scratch's built-in audio capabilities. The following screenshot is a preview of our slideshow:

Our second story project takes a more classical approach to tell a story by creating a book with a table of contents and then animating the individual scenes as a way of narrating the story.

Building games

Games are by the far the most popular Scratch project, and people tend to create all the normal types of games: platformer games, scrolling backgrounds, role-playing games, mazes, and classic arcade games. We'll remix the classic Pong game into a challenging game of Breakout, and in the process, we'll set the stage for many common game-programming concepts. The following screenshot shows the Breakout game:

Programming games of chance

We will encounter randomness throughout the book, but we'll develop a project that applies random outcomes to an interactive story. The following screenshot shows a Trip to the fortune teller:

Creating art projects

The Scratch site is loaded with talented illustrators, and Scratch provides all the tools needed to draw characters and scenes, namely a paint editor and an easy way to animate them. The other kind of art you'll find on the Scratch site is computer-generated art, and we'll spend time drawing geometric shapes, as seen in the following screenshot:

Sensing the real world

Scratch has historically included support for add-on hardware, such as PicoBoard and LEGO WeDo. Scratch also includes built-in support to use the computer's webcam and senses external sounds using the computer's microphone. We'll explore the webcam, microphone, and PicoBoard in our project.

Programming concepts

The following table summarizes several programming concepts that can be learned with Scratch. It's included here primarily to reinforce Scratch as a programming language and foreshadow the concepts we'll use throughout the book. We'll introduce concepts in greater detail as we work through the book.

Concept

Description

Interface design

When we design a program, we turn our imagination into a creation that can be shared with others. We create the flow of the program, how the user interacts with the project, and the actions each sprite takes to tell our story.

Loops (iteration)

A loop repeats (iterates) through a list of programming commands (also known as blocks in Scratch). Often, we'll use conditional statements to control when and how often a loop runs.

Boolean logic

A Boolean command evaluates a given statement as true or false. In Scratch, a Boolean command can check whether a specified condition is true (for example, is the color blue?), or we can compare values with and, or, and not operators. For example, if 4 > 0 and 4 < 2.

Variables

Variables store text or numbers for reuse in the program. For example, if x > 0 creates a conditional statement that evaluates whether the number assigned to x is greater than 0.

Arrays (Lists)

Arrays are similar to variables in that they store information that may or may not change. However, a list stores multiple values in the same way a grocery list stores a group of items.

Events

Scratch provides an entire group of event blocks that allows us to tell our program what to do when that event happens. For example, events include when flag is clicked or when a space key is pressed.

Synchronization and coordination

Programming a sprite to receive a broadcast message from another sprite coordinates a cause and effect. Broadcasting a message and waiting for all the other sprites to act on the broadcast synchronizes the action. Throughout the book, broadcasts are a technique we will use often, and they provide the fundamental communication between the sprites in the project.

Concurrency

Creating two scripts to run on the same control enables parallel execution. For example, programming four different sprites to pixelate when the green flag is clicked creates four concurrent actions.

Random numbers

This concept picks a random number from a specified range.

Cloud data

Scratch 2.0 introduces cloud variables that enable projects to store data on the Scratch web servers so that the data is available to other Scratch users. For example, the use of cloud data might include keeping a high score or tracking the survey results.

Procedures

Procedures can also be called as functions or methods in other programming languages. Scratch 2.0 adds the ability to create custom blocks that allows you to create a stack of blocks under a single name. When you use a custom block, you can pass an argument, such as a sprite number, into the procedure.

Vector and Bitmap graphics

Scratch includes a built-in image editor that enables you to create graphics and sprites for your projects. Vector graphics is a new feature of Scratch 2.0.

Cloning

New to Scratch 2.0, cloning allows a sprite to duplicate itself while the program is running. Clones inherit the parent sprite's costumes and scripts. For example, many people create games that need to shoot something, such as asteroids. Cloning in Scratch 2.0 allows us to shoot multiple times.

Video

By using the computer's built-in webcam, Scratch 2.0 can enable the project to sense the video(s).