In this game you move a character (Gobo) with the arrow keys. In the first round pick up as much fruit as you can before the timer runs out. You will need to remember the order you picked up the fruit in.
In this game you move a character (Gobo) with the arrow keys. In the first round pick up as much fruit as you can before the timer runs out. You will need to remember the order you picked up the fruit in.
In the second round you need to place the fruit in the correct boxes starting with the last fruit you picked up. Again there is a time limit for this round. The game is over if you try to put fruit in the wrong box.
In the second round you need to place the fruit in the correct boxes starting with the last fruit you picked up. Again there is a time limit for this round. The game is over if you try to put fruit in the wrong box.

Step 1

  1. Create a new Scratch Project and call it “Fruit Picker”
  2. Delete the cat sprite and add a new sprite, Gobo, which you can find in the library
  3. 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.
    2 ways to move
  4. Create a sprite called fruit with 4 different costumes – apple, orange, banannas, watermellon (all available in the library)
    We will have just 1 fruit sprite but it will have 4 different costumes
    We will have just 1 fruit sprite but it will have 4 different costumes
  5. Use cloning to make multiple fruit appear on the screen. clone-blockWhen 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. start-clone Use random numbers to position each clone randomly in an area of the screen. random 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.
  6. 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.
    For this sprite only
    Selecting ‘for this sprite only‘ will allow each of the clones to have it’s own version of the variable.

    Use nested if else blocks under When I start as a clone block to store the type of fruit in the type variable.
    nested-if-else

  7. Create a list called inventory. This will be used to store a list of what fruit Gobo has picked up.
    We will create a list called inventory which will store a list of the fruit that Gobo picks up
    We will create a list called inventory which will store a list of the fruit that Gobo picks up
  8. 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:
  9. 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.
  10. 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.

Step 2

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.

  1. 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:
    applesbanannasOrangeswatermelons

    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.

  2. 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’.
  3. 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.wait
  4. 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?)
  5. When the game is over, play a sound and display a graphic that says game over. This can be a backdrop in the stage.
  6. Make a high score variable that gets updated if the score is greater than the high score.