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

Dealing with collision events


Now that we have a collision mask, we can have our kart respond differently, depending on where it is driving. When on the road, the kart will increase throttle up to full speed. When hitting the sandbox it will be slowed down, and hitting the walls is even worse. The kart will bounce back and completely lose momentum.

Let's build these responses with a few scripts.

Engage thrusters

We will add a series of script instructions to the player1 sprite. We will assemble the instructions first, then place the script segment at the right spot in the existing script:

  1. Start with an if () then block.

  2. For the condition, we will check touching color ()?.

  3. Click on the color box and then on the sandy color of your collision mask with the eyedropper icon.

  4. Inside the if () then block, place a set <speed1> to () block.

When the kart drives through sand, we will slow it down. We do this by multiplying its current speed with a number smaller than 1 using these following steps:

  1. Place...