Eating and gaining health points

This code snippet can be used to have food that your character can eat, and gain health from.

To set this up, you will need a health variable. The bite sound is optional, but can be found in the standard scratch library

The code works by constantly checking if the sprite is touching the food sprite. If it is, it will increase the health, make a biting sound, and then broadcast an eat message. This broadcast then makes the food sprite hide.

The code can be found here:

^This code is put on the main sprite
^ This code is put on the food sprite

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top