Adding scripts to the food sprite
For each platform, we will create clones of food sprite. To make the game more interesting, the food clones are randomly placed on its assigned platform and scroll with that platform. If the player sprite eats or touches bad food, then the player dies and the game ends. For all other food types, eating food will earn the player one point.
Prepare for lift off
Before diving into the scripts, we need to take a look at the food sprite costumes, as well as their scrolling mechanism.
The costumes of the food sprite are grouped into bad and good food, with bad food at the front of the costume list. The good_food_start_cos_idx
variable defines which costume index is the starting index of good food costumes. We will use good_food_start_cos_idx
later in the scripts to determine whether Marco eats a bad food sprite.
As shown in the following screenshot, if good_food_start_cos_idx
is set to 3
, then food sprites with Red Mushroom or Green Mushroom costume would be bad....