You will add an insect for the dragonfly to eat.
There’s a fly in the Frog 2 sprite that you can use.
Add the Frog 2 sprite to your project. Rename the sprite to Insect
:
You only need the fly, not the frog.
Click on the Costumes tab. Click on the fly to select it and click on the Copy icon.
Add a new costume to the sprite using the Paint option:
Click on the Paste icon to paste the sprite into the new costume. Drag the fly to the centre so it lines up with the crosshair.
You can rename your costume Insect
and delete the other costumes, as you won’t need those:
Increase the size of the fly so that it’s easier to see and catch:
Click on the Code tab and add a script to make the Insect sprite bounce around:
The if on edge, bounce
block checks to see if the sprite has reached the edge of the Stage and points the sprite in a different direction if it has.
You want the Insect sprite to hide
if
it gets eaten by the Dragonfly sprite.
Add an if
block to the Insect sprite’s movement script:
The if
has a hexagon-shaped input. This means you can put a condition here.
When the
block runs, Scratch will check the condition. If the condition is ‘true’ if
then
the code inside the
block will run.if
You want the insect to hide
it is if
touching
the Dragonfly sprite.
Drag a
into the touching
[Dragonfly v]
block. Add a if
hide
block inside the
block.if
Test: Test your code and control the dragonfly to eat the fly. The fly should disappear.
The dragonfly won’t get very big if it can only eat one fly!
Add blocks to go to a random position
on the Stage, and make your sprite wait
for one second then show
:
Test: Test that your dragonfly can now eat lots of flies.
Make sure you have added the show
block to show at the start.
Tip: You can click the red Stop button above the Stage if you want the dragonfly to be quiet while you add more code.