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

Fighting back


So we can now place cannons that shoot cannonballs in the direction of the mouse cursor. But we still aren't hitting any enemies. Let's quickly fix that problem.

Engage thrusters

We will check when a cannonball and an enemy collide and take proper action accordingly. The steps to do it are as follows:

  1. Inside the cannonball, clone repeat, and place an if … then condition block to check collisions.

  2. Check for collisions by using the touching <enemy> block.

  3. When a cannonball touches an enemy, first wait for 0.05 seconds by using the wait ... secs block. This is to ensure that the enemy has time to respond to the collision as well.

  4. Then we add a delete this clone block to delete the clone.

So cannonballs will not only expire after having traveled a certain distance, but also when they hit an enemy. You could omit this step, but that would make the game a bit too easy because cannonballs can move on and hit multiple enemies, as was the case in the Artillery Game before we fixed that...