Articles

Multiple Levels in a Game: Programming in Scratch 2.0


COLLEEN LEWIS: We can
add multiple levels to our games to make them much cooler. To make it easy to see that
I’m in a different level, I’ll make different
backdrops for my stage. Click on Stage, then Backdrops. And I’m going to make
three different stages. The first one I’ll color all orange. The second one, I’ll color all yellow. And the third one, I’ll color all green. And I’ll name these level one,
level two, and level three. Now I can go back to my scripts. Here, I’m clicked on the stage, so
I can write scripts for the stage. And I’ll make a way to be able
to switch between my backdrops. When the flag is clicked,
I’ll switch to level one. Then I’ll wait to receive a message
that says level two should start. Switch to level two. When I’ve received a
message, switch to level two, I’ll switch to the level two backdrop. And lastly, when I receive the
message, switch to level three, I’ll switch to the level three backdrop. OK, next I’ll add a new sprite to
my project, which will be a door. I’ll use the door to
switch between levels. I’ll click on the Paint
new sprite button. I’ll go back to the scripts now. I’ll move my door to the right. Now I’ll click on the
cat to add scripts for it to be able to walk from
the left side of the screen to the right side of the screen. Looks good. Now I’ll set up a script
to have it change levels. When the green flag is
clicked, I’ll move the cat over to the left side of the
screen, say about here. Then I’ll wait until the
cat touches the door. I’ll rename sprite two, door. And now I can say, wait
until touching door. Once I touch door, I want
to switch to the next level. So I can broadcast a message to say
that we’re switching to the next level. When I start the next level, I want
to have the cat move back to the left. So I’ll get a motions block
and move him back to the left. Then again, I can wait
until he touches the door and then I’ll broadcast
to switch to level three. I can duplicate those blocks,
because I already have those. So now the cat starts on the left, then
he waits until he’s touching the door, and then once that happens, we
broadcast switch to level two. Then we’ll go to x is
-200, y is 0, and we’ll wait until he’s touching the door again. Once he’s touching the door,
he’ll broadcast– oops, this is a bug– switch to level three. Let’s look back at the
scripts for the stage to see how that will
change the backdrops. Here, when the green flag is
clicked, I’ll switch to level one. When I receive switch to level two,
I’ll switch to backdrop level two. When I receive switch to level three,
I’ll switch to backdrop level three. I’ll click on the cat again and
then we can try and run this script. I’ll click on the green flag and it
should switch to the orange level, because that’s level one. I can move the character to the
right and when he touches the door, he should move back to the
left and the background should change to switch to level two. Let’s see. It worked. This second go to x
-200, y 0, has happened. And so we’re just waiting until
he touches the door again. And when he does, we’ll
broadcast switch to level three. And if we look at the stage,
that will switch the backdrop to level three, which is green. Let’s touch the door again. And it switched to the next level. I have a bug here, though. I didn’t move him back to the beginning. Let me fix that. Let me try the whole thing over again. So there we switched to level two. Here we wait until he touches the door
again and then switch to level three. And then here we are on the final
level, which is level three.

Comment here