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 – adding a variable to track lives


As we make the game more difficult, it will be appropriate to provide the player with more than one opportunity to clear the game. We'll do this by tracking the player's lives, as shown in the following steps:

  1. Create a variable named lives. You can create it For all sprites.

  2. Let's set the starting value of the new variable at the start of the game. Select the ball sprite. Then, add a set () to () block to the when flag clicked stack, which sets the ball's initial position and direction.

  3. Select the lives variable and enter the value 3.

  4. Next, we need to change the logic that ends the game to check for life. To do this, detach the stop (all) block from the wait until (y position) < (y position) of (paddle) block.

  5. Instead of stopping everything, let's decrease the value of the lives variable. Add a change () by () block to the bottom of the stack. Select the lives variable and enter a value of -1 in the by value.

  6. Add a wait until () block from...