In this video,
you will learn how to make the sprites fall.
Start by making the sprite move down
using the change Y by block.
Enter a negative number in that space.
Click on it to make sure the sprite moves down.
Make the sprite keep moving down
until it touches the ground or another stamp.
Each of the backgrounds has a black bar at the bottom
and each of the stamps are black on top.
From the sensing menu, drag out a touching color condition.
Then, click on the color box and on
the black bar at the bottom of the stage.
Now you have a condition that reads, touching color block.
The sprite should keep falling
until it touches the color black.
To make something keep happening
until a condition is true, use the repeat until block.
Place the repeat until block around the change Y by block.
The sprite should stop moving down
when it touches the black.
Place the touching color black condition
inside the repeat until block.
Test this by clicking on the code.
The sprite should fall until it hits the ground.
After the sprite falls, it should stamp itself.
Place the stamp block, under the repeat until block.
Have the sprite make a sound as it lands.
This example plays the sound pop when the sprite lands.
The block also needs to return to the top of the screen
so it can fall and stamp itself again.
Drag the sprite back to its starting position
and then place the go to XY block under the stamp block.
Click on the code to test it.
The sprite will fall until it hits the ground,
then it will leave a stamp of itself
and return to the top of the screen.
To make the game more fun, make the starting
location of the sprite unpredictable.
To do this, try using the random variable
inside a go to block.
The stage spans -240 to 240 from left to right
and -180 to 180 from top to bottom.
So this example uses random -240 to 240
for the X and 180 for the Y.
Click on the code to try it again.
The sprite doesn't fall if it hits another sprite.
That's because the other sprites are also black
and the sprites stops falling when it touches black.
To keep this from happening, use the
when green flag is clicked and hide blocks to make
the sprites disappear when the green flag is clicked.
To make all the sprites perform the same actions,
copy the code by dragging it to each of the sprites.
Test the code by clicking the green flag.
All the sprites hide!
Now, click on the code that makes the sprites fall.
The sprites seem to just appear at the bottom.
Now that it hides when the green flag is clicked,
it needs to show itself before it falls
so that the user can see it fall.
Place the show block above the repeat block.
Test the code by clicking on it.
You can see the block fall!
When it returns to the top of the screen however,
you can still see it.
Place the hide block at the end of the falling code
to hide the sprite when it returns to the top.
The sprite should show up, fall, stamp itself,
go to a random spot at the top of the screen and hide again.
Copy the code to each of the other sprites.
Next, program when this should happen.
The stage can broadcast a message
telling each of the sprites to fall.
Create a different message for each sprite.
Place a when I receive block at
the top of the code for each sprite falling.
Make sure to use the correct message from the dropdown menu.
Go back to the stage.
Click on the code that sends the message.
Each sprite should fall in order, once.
It's hard to build an interesting structure
with each sprite falling only once.
Place a forever loop around the
messages so they keep falling.
Click on the code.
The blocks keep falling.
Add a when green flag clicked block
to start the sprites falling when the green flag is clicked.
Once you've finished this add-on,
update the instructions on your product page
to describe how to play this game.
For this example, it will say,
to play this game, try to build a building
from the blocks that fall from the sky.
Now it's your turn.
Make the sprite fall until it hits the ground
or a stamp using repeat until,
touching color, and change Y by blocks.
Make the sprite stamp when it lands,
then return to the top of the screen.
Hide sprites when the green flag is clicked,
and show them before they fall.
Broadcast and receive messages to make them fall,
place these messages inside a forever loop,
and finally add a when green flag clicked
block to the top of the code.
Create a game in which users create a building using falling blocks.
Make the landscape turn into rainbow colors.
Make the sprites change size!
Change the backdrop to other scenes.
Make the shapes turn and rotate!
Sign in to track your progress and earn badges