Professional Documents
Culture Documents
Make Your Own Mario Game Scratch Basics For Kids and Adults
Make Your Own Mario Game Scratch Basics For Kids and Adults
This ebook is the intellectual property of MakeUseOf. It must only be published in its original
form. Using parts or republishing altered parts of this ebook is prohibited without permission
from MakeUseOf.com.
Watch the YouTube video here: Get Started with Scratch: Drag and Drop Visual Programming
Scratch is a tool that lets you drag-and-drop assets to create games or animations. It’s easy to
understand, but teaches the building blocks of programming in the process. Let’s see what you
can create in Scratch, then walk through the steps to creating a simple Mario game.
Meet Scratch
To get started with Scratch, head to the homepage. You should create an account right away so
you can save your creations. Click the Join Scratch button in the top-right of the window. Create
a username and password, enter your date of birth and gender, then the system will ask for a
parent’s email address. Enter your own if you have one, then confirm your address so you can
comment on other projects and share yours.
Now, you can jump right in. Click Create on the top toolbar to launch the Scratch editor. If you
prefer, you can also download the offline editor to work without an internet connection.
1. Stage — Shows a quick summary of your game. All active sprites and your chosen
background will appear here. You can move sprites around if you like. Give your project a
name in the field above this.
2. Backdrop — Here, you can select a background for your game. Choose from Scratch’s
library, paint your own, or import a file. You can also grab an image from your PC’s
camera, though most people probably won’t need this option.
3. Sprites — The center for all the sprites in your project. Like backdrops, you can add
default ones, create your own, or upload images. Click the little blue i icon on a sprite to
rename it, change its angle, or hide it.
4. Work Area — Where the bulk of your work in Scratch takes place. Use the tabs above
(labeled Scripts, Costumes, and Sounds to change what you’re working on.
2. Costumes lets you create additional poses for your sprites. This tab will change to
Backdrops if you have one selected in area 2, and back to Costumes when you select
a Sprite in area 6. A basic image editor lets you make changes to graphics in your
game. You can rename assets here too.
5. Blocks — Depending on which of the three tabs you’ve selected, this area will switch
between code blocks, sprite costumes/backdrops, and sound clips.
6. Control Buttons — The green flag starts your game, while the red stop sign shape ends it.
You’ll use these for testing.
• Motion — Make the given sprite move, whether by steps, toward another object, or via
direct coordinates.
• Looks — Lets the sprite hide or show itself, switch costumes, change size, or move between
layers.
• Pen — Draw with a marker and change its color and shape.
• Data — Lets you create your own variables. This comes in extremely handy for elements
that Scratch doesn’t have built-in.
• Events — Criteria for kicking off other actions, like when you click the green flag or press
the space bar. You need these blocks to all your other blocks actually do something!
• Sensing — Place these blocks into others to perform actions when a sprite is touching
another element or the user is holding down a key.
• Operators — Math elements that let you perform arithmetic or basic Boolean operations on
variables.
First, you need a cool soccer backdrop. Head into the Backdrop section in the bottom-left and
click the picture icon to choose one of Scratch’s backdrops. There’s one called Goal1 that will
work perfectly. Next, click the sprite icon to add a new pre-made sprite. You should see the Ball-
Soccer in the list — double-click it to add it to your sprites.
Now that the graphics are ready, you need to start with some blocks. Select the cat, since he’s
the one doing the action. Remember that the Events tab holds many of the starting blocks?
Take a look, and you’ll see one that fires when you click the green flag. That’s a perfect starting
point — drag it over into the Scripts work area.
Once you start, you want the cat to run over and kick the ball, right? That sounds like
something that would fall under the Motion tab. You have several options to make the cat
move, such as the Move X steps block. But we can’t guarantee how many steps it will take the
cat to reach the ball. There’s a better block for this — try the Glide X secs to block. One second is
Notice how the Wait until block has an elongated hexagon shape inside it. Many of the Sensing
blocks fit this shape, so take a look at those to find the right one. See the touching block at the
top of the list? You can drag that right inside the hole inside Wait until. Change the drop-down
box to Cat or whatever you named the cat sprite.
Now you just need to make the soccer ball fly into the goal. The Glide X secs to block in the
Motion category that we used earlier for the cat will work fine. Snap that block under wait until,
and place your mouse pointer over the goal net. You’ll see X and Y coordinates underneath the
stage — plug those into the Glide block. The ball should move pretty quickly when kicked, so
let’s try 0.5 seconds for the timing.
You’ll find a block labeled Play sound under the Sound category. Snap that under the glide
block, and you’re all done! Click on the green flag to play your animation. The cat will run over to
the ball, and when he touches it, the ball flies into the goal and the crowd cheers.
That wasn’t too hard! Now that we’ve dug into how blocks relate and fit together, let’s look at
how you can build a Mario game using Scratch.
Please note: Because I’m not an artist, for the purposes of this tutorial I’m copying Mario
sprites from the web. Mario graphics are owned by Nintendo and you should not publish any
game using copyrighted sprites. This is presented as an example only.
Import Graphics
The first step is getting your sprites and backgrounds imported into Scratch. Since we’re using
images from the web, I’ll download them and then upload them into Scratch. Creating logic so
that Mario can jump on enemies to defeat them but dies from touching their sides is too
advanced for this tutorial, so we’ll have him collect coins instead.
At the end of the tutorial, I’ll provide a ZIP file with the final assets I used. If you use those you
won’t have to worry about the image manipulation instructions in the tutorial. If you want to
download everything yourself, carry on. Here are the sprites that I downloaded:
• Mario jumping
• Animated coin
• Ground blocks
• Clouds
Scratch has a Blue Sky 3 background, which will work fine for our needs.
For the ground, you’ll need a lot of blocks since Mario runs along them. Use Paint.NET to grab
the six blocks in the middle of the Ground Blocks image, then save them as a separate file.
You’ll need about 12 blocks to cover the entire bottom of the screen once you shrink them to a
good size. Thus, you should place two copies of these six blocks side-by-side for your Ground
sprite. Upload this and then make two ground sprite duplicates in Scratch.
The coin is an animated GIF, so it’s a little different. Whenever you upload it, Scratch will create
costumes for every frame of the animation. This image has 11 total frames, but unfortunately
also has a white border around it, which looks off against the blue background. You’ll have to
open each costume for the coin inside the Scratch editor. Use the pipette tool to select the blue
background color, then use the paint bucket tool to change the white edges of the coin to pale
blue.
Import Sounds
Just like sprites, we’ll grab a couple of sounds to flesh out our game. Go ahead and download
these, then upload them using the Sounds tab. While you’re at it, look into adding them as cool
ringtones for your phone.
In short, this script sets the coin to its default state when you click the green flag. It then cycles
through the frames endlessly, at a speed you set as the FPS variable in the Data tab. Play
around with that number if you don’t like the speed.
Uncheck the box next to Coin-FPS in the Data tab (this is a custom variable you create) so it
doesn’t show on-screen.
First, you need to make four variables in the Data tab. All four of these are For all sprites except
for Velocity, which is only for Mario:
• Gravity is a constant that pulls Mario back to the ground when he jumps.
Here’s the code block you’ll need for each Ground sprite:
This places the ground at the bottom of the screen, then simply scrolls the blocks as Mario
moves. ScrollX is the position of the blocks; 0 is the default position that launches when you
click the green flag. You’ll notice that you can’t move left immediately after you start.
For the second (and further) ground blocks, increment the 0 digit in ScrollX + 480 * 0 by one for
each new piece of ground. This will offset it so it scrolls smoothly.
This block of code changes the ScrollX variable when Mario moves. Whenever you press left or
right, Mario faces in the appropriate direction and takes a step, incrementing ScrollX by 3. If
you find that Mario flips upside down when you move left, click on the blue i on his sprite and
make sure the Rotation style is set to the second option. This will flip him left and right instead
of in a circle.
A simple bit of code that figures out the OnGround variable. If he’s touching one of the ground
blocks, OnGround equals 1 (true). When he’s jumping, OnGround is 0 (false).
Our last block of code for Mario is all setup. When you click the green flag to start, the music
begins, all variables are set to their default values, and Mario spawns in the middle of the
screen.
This is pretty easy: whenever Mario touches a coin, the collection sound plays and the coin
hides. In the coin animation code, we’ve placed a Show block so the coins re-appear when you
restart.
This places the coin at a Y value (that’s vertical screen position) where Mario can easily grab it.
It then uses similar logic to the ground blocks to scroll towards Mario. Note that we’ve
increased the scroll rate to 0.75 so that coins move towards Mario quickly. For the second and
third coins, we increase the set y to field to -40 and -20 so they’re a little higher up and harder
for Mario to grab. In the Set x to block, increase the 150 * 1 to 150 * 3 and 150 * 5 for the second
and third coins to place them further to the right, off-screen.
Again, this places a cloud at a specific height, then scrolls it as Mario moves. For a second
cloud that’s in front of Mario instead of behind him, change the set x to block to (ScrollX * 0.1)
+ (150 * 1), just like the coins.
Save this as a PNG file and upload it as a new sprite called Border. Since you drew the borders
right over the screen, you can line it up perfectly.
Then, you just need a few blocks so that the border is always in front:
We’ve set up just the basics of a Mario game together. You can add lots of elements to your
game from here. Try adding Super Mushrooms to power Mario up, making some pits that Mario
must clear, or creating an end-level flag. With the building blocks you’ve picked up here, you
can add more sprites, variables, and logic to make anything you want. We’re looking forward to
seeing what you come up with!
We’d like to give a shout-out to Scratch user dryd3418, as we used some of the code from his
Super Mario: Scroll & Jump Tutorial project in our own project for this article. For more detailed
help, including scripts you can copy, check out another user’s guide to making a Mario game. If you
want to take an easier route, check out the Create Your Own Mario Game project that lets you drag
and drop sprites to make a simple game.
Note that on any Scratch project, you can click See Inside to open the project up in an editor
just like you used for your own project. This lets you get a glimpse into the blocks that someone
used to make their project work, and can help you out when you get stuck. I’ve made my project
available to all, so feel free to view it and have a look at the code if you need some help. I’ve also
zipped all the assets I used in this game, so you can download them to save some time.
We want to hear from you if you’ve tried out Scratch! Have you expanded our basic Mario
game? Leave your questions, comments, and updates in the comments below, please!