Mosquito Patrol

Let’s Catch Some Mosquitoes

The parrot moves, the mosquito flies, but they don’t interact: if the mosquito flies right into the parrot’s beak, nothing happens. Time to change that!

First, you need to know if the mosquito is touching the parrot. For this, you’ll need a control block and a sensing block.

Add the if...then control block into the forever loop on the mosquito, below the if on edge bounce block.

Drag the touching... block into the space at the top of the if...then block, and click the little triangle to pick the parrot sprite’s name. If you haven’t changed it, it’ll be ‘Sprite1’.

ifonedge,bounceiftouchingSprite1?then

How does it work?

The if...then control block needs to be given a True/False value.

Sensing blocks collect information, like where the sprite is, what it’s touching, etc. You’re using the block

touchingSprite1?

From this block’s pointy ends, you can tell it’s going to give you the True/False value that the if...then block needs.

Of course, you’ve just added an if...then block with no ‘then’.

You can make the mosquito disappear, as if the parrot ate it, by using the hide block.

Find the hide block in the Looks list, and put it inside if...then.

iftouchingSprite1?thenhide

Now once the parrot catches the mosquito, it disappears for good. That’s not great.

Put the show block from Looks in at the very start of the mosquito code, so you can reset the game.

whenclickedshowsetrotationstyleleft-rightforever

Better, but you don’t want the player to have to restart the game every time they catch a single mosquito!

Update the code inside your if...then block to look like this:

ifonedge,bounceiftouchingSprite1?thenhidewait1secondsgotox:pickrandom-240to240y:pickrandom-180to180show

How does it work?

You are being clever here: when the mosquito is hidden, wait, move it, then show it again.

It looks like lots of mosquitoes, but it’s that one sprite moving around!

That’s a game! But there’s no way to keep score yet…or to win. You can fix that too — in the next step!