Uploaded by aamnahasim

How-to-Make-a-Platformer-on-Scratch

advertisement
instructables
How to Make a Platformer on Scratch
by mmckenzie20
Scratch is a website where people create games and other programs using premade blocks that you drag and drop
to a work space. Today I will show you how to make a platforming game on scratch.
Supplies:
The only thing you will need is a phone or a computer and a browser that can run scratch
Step 1: Create Sprites
Start by logging in to scratch, this is needed so if you
want to publish or come back to the game. Then click
on create and it will put you on the project editor. This
is were we will be making our project.
"sprite" to "player."
On the top left, you will nd the costumes button.
Click it if you want to change your player. Rename
Rename your game to whatever you want.
Then create your platforms by making a new sprite.
Rename that sprite "ground."
How to Make a Platformer on Scratch: Page 1
Step 2: Gravity
Add a "when green ag is clicked." Then Place a "set
position" block and put in the coordinates on where
you want your player to spawn. Get a "forever" loop
and a "repeat until" loop place the "forever" loop
under the "set position" block.
Create a variable. This will act as our gravity. Mine was
name "y vel" (short for y velocity). Right underneath
the "set position" block, place a "set variable to ___."
Change the Variable to whatever you named your
variable (I will be calling it y vel now) and change the
number to zero. Next add a "change y by ___," and put
a "y vel" in it. Put that in the "forever loop." Below that
add a "change 'yvel' by '-1.'"
Create a block called Touch ground. MAKE SURE WHEN
DOING THIS YOU CLICK RUN WITHOUT SCREEN
REFRESH.
Insert a "repeat until" loop below the "touch ground".
Add a "not" in the Boolean and in the "not" add a
"touching 'Ground.'" In that put a "change y by '1.'"
Underneath that put a "set 'y vel' to '0.'"
If you followed all of that, your code should look like
the picture above.
Step 3: Movement
How to Make a Platformer on Scratch: Page 2
Underneath the "when green ag is clicked," put a "set
rotation style 'left-right.'"
Inside the "forever' loop add two "if then blocks." In
the Boolean add two "key ___ pressed." Set it to what
keys you want to go left and right.
Make a block called "x detection" (it will help in next
step). Click run without screen refresh. Add an input,
Create a new variable called "falling." Under "touch
ground," place a "change 'falling' by '1.'" Under that, in
the "repeat until" loop, place a "set 'falling' to 'zero'"
De ne jump. Add an "if then" block. In the Boolean
put a "_____ and ____." In one Boolean, put "key 'what
your jump key will be' pressed," then add "if '5' is
greater than 'falling.'" In the "if then" block, put "set 'y
vel' to '12 (jump height.'"
call it "speed."
In the right direction, put "detection x '5 (how fast you
want your sprite to move),'" (speed depends on what
you want), and "point in direction '90.'" Do the same
for the left but multiply all the numbers by negative
one.
Make a block called jump. Put it in the "forever' loop.
You may notice that your player is not always
touching the ground. Make a new costume, make it
smaller on all sides. Inside the "forever" loop put in
"switch costume to 'costume2 (new costume).'" Below
that, put a "switch costume to 'costume1 (original
costume).'"
If you have done this correctly, this should look like
the picture above
Step 4: Horizontal Collision Detection
Create a new variable called slope. Underneath
"change x by 'speed,'" add a "set slope to '0.'"
loop. In that add a "change x by '0' minus 'speed,'"
then add a "change y by '0' minus 'slope.'"
Add a repeat until block underneath that. Put a
"'touching 'ground' or 'slope' equals '8.'" In that add a
"change y by '1,'" and "change slope by '1.'" Under the
"repeat until" loop, add a "if 'slope' equals '9' then,"
If you did this step correctly, your code should look
like the picture above.
How to Make a Platformer on Scratch: Page 3
Step 5: Vertical Collision Detection
Edit the block "touch ground" add a Boolean, call it
"ceiling." In our "touch ground" in the "forever" loop
add "'y vel' is greater than '0."
'1,'" and "set falling '0.'"
Take everything out of the "repeat until" loop. Put a "if
then else" loop in the "repeat until" loop and add
"ceiling" in the Boolean. In the "if then" part, add
"change y by '-1.'" In the "else" part, add "change y by
If you followed instructions, it should look like the
picture above
Below the "if then else" loop, add a "set 'y vel' to '0.'"
Step 6: Extra
How to Make a Platformer on Scratch: Page 4
Create a new sprite. This will contain the extras.
'message1,'" and put "next costume."
In the forever loop, Get an "if 'touch color red (you
must get the exact color)' then" loop. In that put a "set
position" block. Enter in the coordinates where your
player spawns. Get an "if 'touch color blue' then" loop.
In that put a "set position" block. Enter in the
coordinates where your player spawns. In it as well
broadcast "message1"
You now have the skills to make a basic platformer.
Add to it.
For more help, click the link. He does everything this
talks about, this is his code.
https://scratch.mit.edu/projects/68924432/
In both ground and extras, get "when I receive
Thanks for sharing :)
How to Make a Platformer on Scratch: Page 5
Download