Book Image

Scratch 2.0 Game Development Hotshot

Book Image

Scratch 2.0 Game Development Hotshot

Overview of this book

Table of Contents (18 chapters)
Scratch 2.0 Game Development HOTSHOT
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Adding scripts to Shield and Shield Life


Shield protects and is also protected by the Spaceship. Each time the enemy sprite collides into it, Shield will lose one grid of power, displayed by Shield Life.

When the power is gone (all red), Shield is destroyed and the game is over.

Shield Life displays the shield power grid by changing its costumes, each at a power grid damage level. The technique to display damage level with costumes is to match the costume number with the number of hits. Scratch costumes start from one, instead of zero, so costume#1 depicts zero hit, costume#2 for one hit, and so on.

Prepare for lift off

Shield Life has two local variables: num_shield_hits and num_max_hits. The number_shield_hits variable tracks how many hits the Shield sprite has suffered, and the num_max_hits variable tells the maximum number of hits that Shield can take before its complete destruction.

Engage thrusters

The following steps are used to build the scripts for the Shield sprite:

  1. Add the when <green...