Super Power-Ups!
Now that you have a new power-up working, it’s time to make it do something cool! Let’s make it ‘rain’ power-ups for a few seconds, instead of just giving out an extra life.
For this you need to create another piece of code that will start while the react-to-player
block finishes running. To make that happen, you’ll use a broadcast
block to send a message to another piece of code inside this sprite.
Create this block for the Collectable
sprite. Let’s call the broadcast collectable-rain
.
What does the new code do?
This block just sets collectable-frequency
to a very small number (change it to different values and see what happens!) and then waits a second and changes it back to 1
.
This doesn’t look like it should do much, but think about what’s happening during that second: the when green flag clicked
code is still running, and the repeat until
loop in it is looping. Look at the code in that loop:
You can see that the wait
block here pauses the code for the length of time set by collectable-frequency
. So if the value of collectable-frequency
changes to 0.000001
, the wait
block only pauses for one millionth of a second, meaning that the loop will run many more times than normal. As a result, the code is going to create a lot more power-ups than it normally would, until collectable-frequency
changes back 1
. Can you think of any problems that might cause? There’ll be a lot more super-farts…what if you kept catching them?
Now you have the sprite ready to receive the collectable-rain
broadcast block, but you haven’t made code for sending the broadcast yet.
Next, update the react-to-player
block to look like this, so it broadcasts collectable-rain
when the player touches a type 2
power-up.