Step 4 of 8
50%
Grow to full-size
The Dragonfly needs to grow when it eats a fly.
When you need to let another sprite know that something has happened, you can use a broadcast block as you did in Broadcasting spells.
Add a broadcast block to the Insect sprite with new message food:
![]()
when flag clicked
show // show at the start
forever
move [3] steps
if on edge, bounce
if <touching [Dragonfly v] ?> then
+broadcast [food v]
hide
go to (random position v)
wait [1] seconds
show
end
end
The Dragonfly sprite needs to grow when it receives the food message.
Select the Dragonfly sprite and add this script:
![]()
when I receive [food v]
change size by [5]
Add the Chomp sound to the dragonfly and start it when an insect gets eaten:
when I receive [food v]
+start sound [Chomp v]
change size by [5]
Test: Run your project to test the dragonfly grows and makes a chomp sound when it eats a fly.
When the dragonfly reaches its full size, the game will congratulate you and stop.
Add an if block.
when I receive [food v]
start sound [Chomp v]
change size by [5]
+if < > then
end
The dragonfly is full-size when the size = 100%.
First, add an = operator into the hexagon-shaped input:
when I receive [food v]
start sound [Chomp v]
change size by [5]
+if <[ ] = [ ]> then
end
Finish building the condition by adding a built-in size variable and type the value 100:
when I receive [food v]
start sound [Chomp v]
change size by [5]
+if <(size) = [100]> then
end
Add blocks so that if the condition is true then the dragonfly will broadcast an 'end' message and say I got to full size!
Finally, add a stop all block to stop the other dragonfly scripts:
when I receive [food v]
start sound [Chomp v]
change size by [5]
if <(size) = [100]> then
+broadcast [end v]
+say [I got to full size!]
+stop [other scripts in sprite v] // change from 'all'
end
At the moment, the fly still moves after the project has ended. Add this script to the Insect sprite.
![]()
when I receive [end v]
stop [other scripts in sprite v]
Test: Click the green flag and keep eating flies until your dragonfly reaches full-size.
JuaraKu