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

Adding another ball


A second, and slightly more complex way, of making your game more challenging would be to incorporate another moving ball into the mix. Let's do that here.

Getting ready

To prepare for this, import another ball sprite, perhaps the basketball or baseball. Give this new ball the same script that you gave to the first ball. Also name this ball Ball2 instead of Sprite1.

Both balls will now bounce around the screen, but will seemingly do nothing special when they touch. Now the challenge becomes to make these balls bounce off of each other.

How to do it...

To accomplish this task, start with either sprite's script area. Ultimately, we'll add the same script to the other sprite too.

Tip

Note that you can right-click on a sprite and click on Duplicate to save time.

  1. Drag over a second green flag block.

    Thus we're starting another sequence of code.

  2. Drag a forever block underneath the previous block.

  3. Inside our forever loop, drag an if () then block, also from the Control category.

  4. Inside...