Book Image

Scratch Cookbook

By : Brandon Milonovich
Book Image

Scratch Cookbook

By: Brandon Milonovich

Overview of this book

Scratch 2.0 is an easy to use programming language that allows you to animate stories and create interactive games. Scratch also gives you the capability of using programming to calculate complicated calculations for you. Scratch Cookbook will lead you through easy-to-follow recipes that give you everything you need to become a more advanced programmer. Scratch Cookbook will take you through the essential features of Scratch. You'll then work through simple recipes to gain an understanding of the more advanced features of Scratch. You will learn how to create animations using Scratch. Sensory board integration (getting input from the outside environment) will also be covered, along with using Scratch to solve complicated and tedious calculations for you. You'll also learn how to work through the exciting process of project remixing where you build on the work of others. Scratch Cookbook will give you everything you need to get started with building your own programs in Scratch that involve sounds, animations, and user interaction.
Table of Contents (17 chapters)
Scratch Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

User interaction with a game


One of the main requirements for most games, or at least the good ones, is that there exists some sort of user interaction. Here, we'll create a new sprite that moves up and down on the boundary we created. This will prevent the balls from hitting the boundary, and thus creates a basic game for us. This is similar to the classic 'pong' bat and ball game, one of the earliest video games ever created.

Getting ready

We first need a sprite that will be controlled by the user. Under the stage, near where we select to import a new sprite, click on the second button to paint a new sprite.

The familiar Paint Editor dialog box will appear. Click on the same rectangular tool we used before and change the color (we're going to use red). Draw a small rectangle in the middle of the screen, similar to the following screenshot:

Notice the three buttons in the upper-right corner?

It is critical that you use the third button to mark the center of your box you just created.

The new...