The Healthy Eater
This is a silly game about eating healthy snacks and avoiding the unhealthy snacks.
The game is relatively simple to make. It spawns random images with the sprites - a technique which can be reused in other game contexts.
As with the other games, we are building our program around a series of functions. This makes our code more readable and easier to work with. You find the blocks for functions by clicking the Advanced section.
The two variables at the start store images. You can find these blocks under Advanced, Images.
One of the images needs to show the character with its mouth open.
Remember, you do not add more than one On Start event. When you see this later on this page, you are adapting this code, not starting again.
We're just defining two lists of images in these blocks.
We will need to add a function call in our existing on start event. Don't add the on start block again, add the block to the one you already have.
Check that this works. The mouth should open and close. When the mouth is open, the player can eat, when it is shut, the player will not eat. We will code for this later.
Here are two functions for spawning the snacks. Click on the images to view a larger version.
These functions use a basic technique for picking a random image from a list. It's quite a handy way to get variety in your game without having to write code for each separate sprite.
The numbers 750 and 1500 mean that unhealthy snacks spawn twice as often as the healthy ones. They also move more quickly. These are values you can choose to tweak in your game.
The Game Part
Start by adapting the On Start. Do not add another one, just add the extra blocks to the one you already have.
There will be a countdown. This will give you a small amount of time to eat fruit or you will die. This puts pressure on the player to be eating when there is unhealthy food around.
Challenges & Extensions
- Change the timings, the sprites, the sounds and so on. Make the game your own. Perhaps you might change the theme so that you catch things instead of eating them. Make your choices.
- The countdown and the speed of the food items is currently fixed. If you were to make variables for these things, you could alter them during game play. Since there is only one place where the score increases, you could add an IF statement here that captures when the score reaches a certain threshold. That might be the moment that you shorten the countdown or speed up/slow down the food.
- You could make a gauge that you could aim to fill when you have eaten enough food of a certain type. You could extend the countdown and give a time limit for eating the correct type of food, lowering the value should you eat the incorrect type. This is quite a challenging feature to try to implement.
- The game here is quite simple. You might consider merging this idea with something else you have been making that feels equally small or incomplete. This could be a boss level of some sort.