At this point, you should have built a story that takes place in a stormy day setting.
In this add-on, you’ll broadcast an earthquake to really shake up your story.
First, you’ll need to find a way to make the earth shake.
Click the earth sprite, and select the motion menu.
For this earthquake, you’ll program the earth to move left and right repeatedly. To do this, you’ll need blocks that move the sprite left and right, and a way to make them repeat that motion. Drag out two “change x by” blocks. X coordinates represent left and right positions on the screen, so if you change the x position of a sprite, you’re moving it left or right. Also, make sure to use the “change” blocks, as the “set” blocks won’t allow you to continually move the sprite.
Click one of these blocks. Great, the sprite moved right.
To move the sprite left, change the other block to a negative number.
Perfect! Now you have a way to move the earth sprite left and right. Next, program the sprite to perform that action repeatedly. Click “control,” and drag out a “repeat 10” block. Put the two “change x by” blocks inside the “repeat 10” block. Click this block stack to try it out. Oh no!
Nothing happened! That’s because this code runs so fast that you can’t see what it does. To fix this, add two “wait” blocks to your code to make the program pause after each left and right movement of the earth sprite.
Try it out! Well, you can see it moving now, but it’s way too slow! Make it faster by shortening the wait times. Great! How about making it a little longer, though? Try repeating it something like 30 times.
Nice! That looks like a good earthquake.
Tinker with these numbers until you have an earthquake that you like.
Finally, you need an event to tell the computer when to run this code.
If you want the earthquake to happen in the middle of your story, you’ll need to broadcast an event to make that happen. Drag out a “broadcast” block, and place it in a spot in your story where you’d like the earthquake to happen. Change the message name to “earthquake.” Click back to the earth sprite, and add a “when I receive earthquake” event. Awesome, try it out!
Consider continuing to build your story events around this earthquake. What might happen after the earth starts shaking? Now, it’s your turn: 1) Use “change x by” blocks to program the earth to move left and right.
2) Use a “repeat 10” block and “wait” blocks to make the earth appear to shake.
3) Broadcast the earthquake in your story, and use a “when I receive” event to make sure it happens.
Finally, consider building your story around this new plot event.