How to Make a Jumping Game in Scratch | Tutorial
How to Make a Jumping Game in Scratch | Tutorial
In this tutorial, you can learn how to make a game in Scratch — a game where a character jumps over moving obstacles to score points!
Try it out:
https://scratch.mit.edu/projects/editor
Music: “Pacific Sun” by Nicolai Heidlas, Creative Commons Attribution 3.0 Unported. https://creativecommons.org/licenses/…
Content
0.14 -> - Hi, everyone.
1.01 -> It's Zoe from the Scratch team.
2.27 -> Also known as Zinnea.
3.49 -> Today,
4.743 -> I wanted to show you how to
make a jumping game in Scratch.
6.78 -> By the end of this tutorial,
7.86 -> you'll be able to make
a game like this one,
9.51 -> where you can have a
character jumping over
11.28 -> moving obstacles.
12.16 -> We'll do this in five steps.
13.93 -> Make your character jump,
15.499 -> make a moving obstacle, stop the game,
18.47 -> add more obstacles, and keep score.
20.8 -> Let's get started.
21.633 -> So first, let's pick a
character, and make it jump.
24.18 -> You can pick any character you
want. I will pick the chick.
27.9 -> And let's also choose a
backdrop. I'll use the blue sky.
30.89 -> To make the character jump upwards,
32.79 -> we can use this block,
33.93 -> change y by 10
36.07 -> And if we make it repeat that 10 times,
38.23 -> it'll go up really high.
39.84 -> Now, we also want it to come back down.
41.75 -> To do this, we can, change y by -10.
45.01 -> And let's put that in a repeat loop, too.
47.91 -> Nice.
48.743 -> It would be fun for the character to jump
50.13 -> when we press the space key,
51.53 -> so we can add the,
52.71 -> when space key pressed
53.9 -> block on top.
54.77 -> And then, we can make a jump with space.
57.23 -> We can also enhance the jump
by making it play a sound,
60.12 -> so we can just add this block,
61.36 -> start sound Chirp
63.376 -> (bird chirping)
Nice.
64.89 -> Now our character can jump.
65.96 -> Next, let's make a moving obstacle,
67.61 -> so our character has
something to jump over.
69.64 -> First, let's pick an obstacle.
71.18 -> It could be anything you'd like
it to be. I'll pick the egg.
73.84 -> I'm actually gonna make
the egg a little smaller,
76.04 -> by setting it size to 80.
77.47 -> You want the obstacle to be a bit smaller
79.19 -> than your character, so your
character can jump over it.
81.48 -> Now,
82.313 -> we want our obstacle to start
at this side of the screen,
84.63 -> and glide over to this side of the screen.
87.16 -> First, how do we tell the
egg to start over here?
90.69 -> We can tell it to go to a
certain position with this block,
93.33 -> go to x and y
94.78 -> In Scratch,
95.613 -> every position on the stage
has a certain number X,
98.98 -> and a certain number Y.
100.75 -> In case it's your first time seeing this,
102.22 -> X represents how far your sprite is,
104.03 -> from this side of the screen
to this side of the screen,
106.18 -> so side to side,
107.18 -> and Y represents how
high up your sprite is.
109.34 -> So, we need to tell the egg to
go to this spot, right here.
111.95 -> Here's an easy way to do that.
113.09 -> Just drag the egg to
where you want it to go,
115.49 -> and then the
116.323 -> go to
117.156 -> block in the menu over here,
118.28 -> actually updates to the
exact X and Y of that spot.
122.27 -> So, we can just drag this block out.
124.8 -> And then to make the egg
glide across the screen,
127 -> we can use this block,
128.18 -> glide to X Y
129.32 -> which makes a sprite glide
smoothly to a certain place.
132.12 -> We want the egg to glide to here,
134.07 -> so we can just drag the egg over here,
136.43 -> and then this glide
block in the menu updates
138.83 -> to the X and Y of this spot.
140.52 -> So, we can just drag that out, too,
143.19 -> and connect it.
144.19 -> And now the egg can
glide across the screen.
146.88 -> Now, the egg glided once,
148.55 -> but we want more eggs to keep coming.
150.57 -> We can do that by putting
this in a forever loop,
152.9 -> and let's make this start
when we click the green flag.
155.02 -> Gliding across the
screen in just one second
156.92 -> is a little fast,
157.84 -> so let's make the egg take three seconds,
160.09 -> to glide across the screen.
161.27 -> Now we can jump over obstacles.
162.79 -> Next, let's make the game
stop, if we run into the egg.
165.8 -> There's this block,
166.633 -> stop all
167.466 -> that will stop everything in your project.
169.56 -> And we can make the egg wait
until it's touching the chick.
173.74 -> And then if it does run into the chick,
176.03 -> have it stop the game.
177.42 -> Let's try that out.
178.253 -> I'll purposely not jump.
180.32 -> There you go. Everything stopped.
181.7 -> Oh, and let's fix this problem.
183.54 -> Sometimes the chick gets stuck in the air,
186.81 -> because its code gets stopped
when it runs into the egg,
189.82 -> but it might not have been
finished with its jump,
191.46 -> so it's just frozen there.
192.53 -> So, we can fix this by making the chick
193.99 -> go to a starting position,
when the game starts.
196.97 -> So, I'll put my chick
where I want it to start,
199.3 -> and then I will drag out a
201.42 -> go to
202.253 -> block, which will be set to
that X and Y of that spot.
205.16 -> And make that happen when
you click the green flag.
207.198 -> (bird chirping)
There we go.
209.57 -> Now, to make our game even more fun,
211.24 -> let's add more obstacles.
212.51 -> It's actually really easy to do that.
214.02 -> Just right-click on the egg, and click,
217.44 -> duplicate
218.273 -> Now we have another egg,
219.57 -> with all the same code as the first egg.
221.23 -> So, it will glide just
like the first egg does.
223.48 -> Let's try it out.
224.89 -> So, we can't see the second egg,
226.91 -> and that's because it's right
on top of the first egg.
229.78 -> They have the exact same code,
231.1 -> so they're gliding at the exact same time.
233.01 -> So, let's make the second
egg wait one second,
235.39 -> before it starts gliding,
236.67 -> so that they're spaced
out from each other.
238.37 -> Now, this looks good,
239.56 -> except this egg is just sitting
in the middle of the screen,
242.65 -> while it waits for one second.
244.01 -> So, let's make it,
244.843 -> hide
245.676 -> when the project starts,
so it'll be invisible,
247.47 -> and then make it,
248.303 -> show
249.17 -> once it's done waiting.
250.91 -> That looks much better.
251.96 -> And lastly, let's add a score,
so the player earns points,
255.4 -> every time they jump over the egg.
256.75 -> To do this, let's make a variable.
258.8 -> In Scratch,
259.633 -> you can use a variable to keep track
261.38 -> of a certain number in your project.
263.34 -> So, I'll make a variable called,
264.53 -> score
265.363 -> and we'll use it to keep
track of the player score.
267.16 -> Every time the player
manages to complete a jump,
269.25 -> we can increase their score by one.
271.055 -> (bird chirping)
Nice.
272.66 -> And when the player loses
and the project restarts,
275.02 -> we can set their score back to zero.
277.02 -> There we go.
277.97 -> That's a jumping game.
278.98 -> I hope this tutorial helped you out.
280.3 -> There are lots of other
things you could try.
282.11 -> You could have multiple
kinds of obstacles,
283.84 -> you could have, once the
player reaches a certain score,
286.31 -> the backdrop changes, so it's
like they went to level two.
288.76 -> I can't wait to see all
the things you make.
290.53 -> Well, I'll see you next
time, and, scratch on.
293.814 -> (lighthearted music)
Source: https://www.youtube.com/watch?v=1jHvXakt1qw