- Create a new Scratch Project and call it “Fruit Picker”
- Delete the cat sprite and add a new sprite, Gobo, which you can find in the library
- Make it so that you can move Gobo with the arrow keys. Use a forever loop and key press sensing for making Gobo move. This gives smoother movement than using the When Key Pressed events.
- Create a sprite called fruit with 4 different costumes – apple, orange, banannas, watermellon (all available in the library)
- Use cloning to make multiple fruit appear on the screen. When we do cloning we usually hide the original sprite that we are using to make the clones from and then show the individual clones in the When I start as a clone event. Use random numbers to position each clone randomly in an area of the screen. Use a random number between 1 and 4 to pick which costume to display so that we have 4 different types of fruit spread randomly around the screen like in the first picture above.
- Make a variable called type to be used by the clones to store the name of the type of fruit that the clone represents. IMPORTANT: When you create the type variable make sure to select the option For this sprite only.
Use nested if else blocks under When I start as a clone block to store the type of fruit in the type variable.
- Create a list called inventory. This will be used to store a list of what fruit Gobo has picked up.
- Add a forever loop under the When I start as a clone block. Inside this forever loop check if the fruit is being touched by Gobo. When it is touched, hide it, add the fruit type to the inventory list, play a sound effect (chomp is one you can use for this) and then delete the clone. At this point you should have something like this:
- Add a score variable and make it so that you increase your score every time you pick up a fruit. Make it so that you get more points for each fruit you pick up, e.g. 1 point for the first fruit, 2 points for the second fruit, 3 points for the third and so on.
- Add a time variable and make it so that it starts off at 10 seconds when the green start flag is clicked and then times down to 0 and broadcasts a message. The stage is a good place to put general game control code like this that does not belong in a particular sprite.
Now we are going to build the second part of the game – after picking the fruit Gobo has to place them in boxes in the correct order.
- Let’s add a sprite for each box. We will need 4 box sprites, one for each type of fruit. Each box sprite should have separate costumes showing different amounts of fruit in the box. The box will start off empty and then when Gobo adds a fruit the costume goes to the next costume showing the amount of fruit in the box. To save you time creating these sprites you can upload the sprites from here:
If you are having difficulty saving and uploading these, you can just get them from this Scratch project and use the ‘Backpack’ to copy them in to your project.
- Add code to the box sprites to check if Gobo is touching. If he is touching you need to check if the last fruit in the inventory matches the box. So if it’s the box of oranges you need to check if the last fruit in the inventory is an orange. If it is an orange, remove it from the inventory list and add it to the box. To remove it from the inventory list use the block delete last of inventory. To add it to the box just use next costume. Also play a sound and increase the score. (Challenge: can you make it so that the score for a correct fruit placement gets bigger for each fruit that you correctly place in a box?) If the last fruit in the inventory is not a match for the box its game over – broadcast a message ‘game over’.
- You will be doing this checking inside a forever loop so while you are touching the box after it checks the last item in inventory it will immediately check the next item without giving you a chance to move away and game will be over right away. So we need to pause the forever loop after one check and wait until Gobo moves away.
- Set the time variable to give you 20 seconds to put the fruit in the boxes, then the game is over. (Challenge: can you make it so that the game is also over when the inventory list becomes empty?)
- When the game is over, play a sound and display a graphic that says game over. This can be a backdrop in the stage.
- Make a high score variable that gets updated if the score is greater than the high score.