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

Time for action – detecting when we clear the level


How do we know when the level is over? The answer is simple, that is, when all the bricks are broken; so, let's build the simple answer. We know that at the start of the game, there are 40 bricks on the screen. Let's follow the given steps to detect when we clear the level:

  1. The cloud id variable has a record of the total number of bricks we built. Let's assign that value to a new variable named level hits. Then, we'll actually count down the level hits variable with each broken brick.

  2. Select the brick sprite. Add the set () to () block to the end of the stack that uses the lay brick custom block. Select level hits as the variable and drag the cloud id reporter block from the Data palette to the to value. Check your blocks against the following screenshot:

  3. Each time the ball breaks a brick, we will reduce the value in the level hits variable. Add a change (level hits) by (-1) block after the change (score) by (1) block in the when I start as...