# Catching bananas

There is a monkey in our programme and he is hungry.  Help him catch the bananas that are falling from the light.
Move your hand in front of the mBot to move the monkey.
Good luck!

You will learn

• How to move a sprite by using the mBot’s distance sensor.

Open the mBlock programme on your computer, turn on your mBot and connect.

### PREPERATION

Check the steps in "execute". Answer the following questions:

• Which steps should I follow?
• Which steps can I take?
• How much time do I need?
• What tools do I need?

### EXECUTE

Perform the steps one by one. Have you forgotten how to do it? Look at the hints or download the solution.

## STEP 1

### The monkey is out of the bag

Remove the sprite and add a monkey, along with a bunch of bananas.

We want to programme our monkey so that he moves along the x-axis.  Meaning from left to right.  Thanks to Scratch, you already know which block you can use for this.

The value that our programme will receive, will depend on the distance between your hand and the mBot's ultrasonic sensor. We want the monkey on the screen to move from - 200 to + 200. We move our hand at a distance of 3 cm to about 30 cm from the mBot.

To transfer these values, we will need to create a variable and convert everything. We have already made the conversion for you.

(distance measured from the ultrasonic sensor x 15) - 250

Create a variable: distance in the mBot page (not the sprite!)

Now set the variable distance to the distance of the mbot sensor.

Try to make the programme.

Go back to the monkey sprite.

Use these blocks to move the monkey.

These are just a few blocks. Do you know which blocks you can use for this? Give it a try.

## STEP 2

### Let's go !!!

Now that our monkey can move from left to right, we will make sure that he has something to eat.

Go to the banana sprite.

His bananas simply fall from the sky.  Meanwhile, we will give you some tips on how to get started.

• the bananas must appear on the upper part of the screen (y-axis).
• on the x-axis, they may appear at random.
• They must fall down.  Therefore, Y must be reduced by...
• They must fall until they’re on the ground.  In other words: they must touch the edge of your screen.

Weet je wat je moet doen? Goed zo!

Do you know what to do?

Done? On to the next step.

Every time a banana reaches the ground, a new immediately appears.  Do you want to change that?  Set a block "wait ... seconds" before your "display" block. If, for the number of seconds, you choose a block "random number between ... and
...”, the bananas will fall down less predictably.

## STEP 3

### Taking scores

The game is already loads of fun, but it might get even more fun if you can keep count of the score.

We have already done this multiple times during the previous exercises.  We will briefly repeat this.

• create a variable
• every time you press the flag, the score turns to 0
• if you hit the monkey, you get a point
• the bananas must also disappear if it hits the monkey

There are endless possibilities with this exercise.

Can you make the mBot play a sound every time you take a banana? Or,
the higher your score, the brighter the LEDs will begin to shine.
Be sure to give it a try.

Good luck!

### REFLECTING

Look back at the project you just made. Ask yourself the following questions:

• Does the programme work like I expected?
• What is working well?
• What is not working well?
• How can I do things differently?