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.
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. Food sprites with all other costumes are good.
To make the game harder, increase the value of good_food_start_cos_idx
, say to 4. Then donut would be considered bad as well—if it tastes so good, it has to be bad, right?
We will create scripts for the following:
Perform the following steps to handle the <green flag> click:
good_food_start_cos_idx
, new_grid_idx
, num_food_per_grid
, and num_costumes
. good_food_start_cos_idx
is the starting costume ID of the good food group. new_grid_idx
is for the next platform index to be used for a new clone. num_food_per_grid
is the number of food clones to create for each platform. num_costumes
variable is the number of costumes the Food sprite has.3
in the set <good_food_start_cos_idx> to () block.0
in the set <new_grid_idx> to () block.4
in the set <num_food_per_grid> to () block.8
in the set <num_costumes> to () block.Perform the following steps to handle the level_start
message:
1
.Perform the following steps to initialize a clone's look and location when it starts:
-240
and 240
respectively.8
. The costumes with index ranging from good_food_start_cos_idx
to num_costumes
are good. The variable bad_food_start_grid_idx
controls whether bad food should show in this grid. For example, if the value of bad_food_start_grid_idx
is 2, then bad food will show from grid 2 and up. This is to tweak the Hunger Run difficulty level. If bad_food_start_grid_idx
is low, bad food would show sooner, thus the game, harder.1
and 8
respectively. The costume selection set includes bad food.-120
in the go to x: my_start_loc_in_grids y: () block.Perform the following steps to scroll with the platforms:
230
. Then, add the hide, else, and show blocks accordingly. Instead of 240
, we use 230
to avoid clones getting stuck at the edge because their position never gets larger than 240
or smaller than -240
. You can test it out on your own by changing the value to 240
to see the undesirable "sticking" effect.Perform the following steps to handle collision with the player:
bad_food_eaten
message.1
. In other words, if the player sprite eats a good food item, then they earn one point.We have created the code to handle the <green flag> click, to handle the level_start
message, initialize the look and location, scroll, and handle collision with the player. To test the scrolling, you can build a block as shown in the following screenshot, and double-click on it to start auto-scrolling:
3.15.206.25