Please note: This theme has not been updated to reflect Scratch 3.0. Visit this help article for more info.
Transcript

In this add-on, you will make random rocks fall from the sky.

The hero has to be quick to avoid getting smashed.

Make a new sprite.

There are rocks in the Scratch library, or you can draw your own.

Then, program the boulder's motion.

Drag out a go-to block and set the y value to 180.

Then, in the x blank, drag a pick-random block.

Tinker with the values in this block to change where the boulders show up.

The example uses negative 100 and 240, so the boulders can appear anywhere in front of the hero.

Click the block stack a couple of times to test.

See that the boulder jumps to different starting places.

Next, program the boulders to descend.

In this example, it will fall at a constant speed.

Put a repeat loop below the go-to block and put a change-y block into it.

To fall, the boulder has to go in the negative y direction, so put a negative 10 or another negative value in the change-y block.

You can always tinker with this value later to see how it changes the boulder's behavior.

Click to test.

Hmm, it started out all right, but it stops too soon.

The top of the stage is where y equals 180.

At the bottom of the stage, y equals negative 180.

If you are in the middle, you can go 180 in either direction which means the height is two times 180, which is 360.

To figure out how many times to descend, divide 360 by the distance the sprite moves each time.

In the example, it moves by 10 steps each time.

360 divided by 10 is 36, so type 36 in the repeat loop.

Test it again.

It stops right where it should.

Great.

Snap a when-I-start-as-a-clone block at the top of the block stack, and add a delete-this-clone block at the bottom.

Test it out by clicking Create a Clone in the Control menu.

The boulder should also do some of the same things the bug does, so click on the bug and copy some code over.

Right-click the hide block under the when-flag-clicked block, click Duplicate, then drag that block to drop it on your new boulder sprite.

That gives you a copy of just that part of the code, which is what you need.

Click back to the boulder.

Get a when-flag-clicked block and snap it into the stack that starts with hide.

That will make the boulders appear randomly, just like the bugs.

Also, add a show block to the top of the when-I-start-as-a-clone stack.

Test all your new code by clicking the flag.

See if the boulders fall.

See if you can run away from them.

You can't.

Add some code to fix that.

If you look at the ground or the cloud sprites, you'll see they both receive the forward message.

The cloud looks a little simpler.

You've probably seen it floating by as the hero moves.

Use the same concept to make the boulders move.

In fact, in the spirit of reusing code, go ahead and drag that block stack to the boulder sprite.

The parallax activity discussed how things that are farther away appear to move slower, which is what the cloud does.

It moves five steps for every 10 steps the ground moves.

Since the boulders are falling right on top of the ground, they should move as fast as the ground.

So type negative 10 into the move block.

The rest of the stack was for making the cloud sprite restart on the right side of the stage, which the boulder shouldn't do.

So discard it.

If everything works, you're done.

Good work, animator.

Now it's your turn.

Program the boulder to go to a random spot at the top of the stage, then fall.

Use the code from the bug to make random clones of the boulder.

Copy the code from the cloud to make the boulders respond to the hero's movement.

Choose an Add-On

Game Over

Give your hero a set number of lives.

Laser

Program your hero to shoot lasers to vanquish the evil bugs.

Power-up

Add a power pellet to make the hero jump higher.

Falling Rocks

Add a falling obstacle to your game.

Platforms

The terrain of your game will change to move up and down.

Follower Friend

Add a cute buddy who follows your hero around.

Instructions

  1. Choose an add-on, and click "watch" to learn how to customize your project.
  2. When you finish, come back to the add-ons screen and try another add-on!