In this tutorial, nosotros're going to acquire how to make a Mario game in Scratch. Super Mario Bros, released in 1985, is arguably one of the most popular video games of all time, and the affiche child of not only the entire Mario franchise, but, to a degree, Nintendo as a whole. Super Mario Bros belongs to an extremely pop genre of arcade games: the Side-Scrolling Platformer.

'Platformer' refers to the way a player must navigate obstacles in whatever given level of the game, oftentimes by literally jumping on platforms. And a truthful 'Side-Scroller' is defined by the way the role player continuously reveals new parts of a level by moving their character towards the right side of the screen.

Another common version of a Side-Scroller is one in which a level (or 'globe,' to apply Mario terminology), is broken up into parts, and to get to a new part, you must accomplish the stop of the previous part. This is the type of Side-Scroller we'll exist building today!

We'll also focus on building a game that will be easy to expand on. When game developers build a game, they often first build a game 'engine'. The engine is sort of like the bare bones of the game; it determines graphics, and how sprites movement and interact.

Super Marios Bros ii was released in 1988, just three years later on the original. Nintendo didn't build a whole new game from scratch, they simply expanded on the first game. They added new sprites and levels, some new features as well, simply the gameplay was very similar. With a good game engine, y'all can build countless games that volition all be fun and like shooting fish in a barrel to build! Nosotros'll expect at some strategies in this tutorial to brand our Scratch coding game easy to build on.

If you're looking to better your coding skills with a fun claiming, don't miss out on our fun Easter Scratch special 1-hour small grouping class! To design even more cool games, join our free Scratch classes for kids:

How to make a Mario game on Scratch stride past step

To create our Mario game today, we'll be using a lot of broadcasting and messaging, and a lot of Ten and Y positions. We'll also learn some advanced techniques for creating platformers, and focus on keeping our game easy to edit and add to. Hither's the Finished Project.

You can absolutely follow along with this tutorial by creating your own Scratch project, but if this is your first platformer, we recommend remixing our Starter Project, which has all of the Sprites and Costumes already put together and sized correctly. We'll still demand to write all the lawmaking though! (Note: if you create your ain projection, then the X and Y positions you employ in your code volition likely demand to exist different than the ones used in this tutorial)

one. Set up assets

We're going to offset building this game by getting our images and backgrounds in gild. Let's create a new backdrop called 'Assets'. We won't really utilize this properties, simply it volition contain all of our custom drawings nosotros'll utilise for sprites and creating backgrounds. Information technology will be easier to build our game if nosotros have everything in one place. Games that are built on the same game engine will often use either the same assets, or very similar ones.

Once we have everything drawn, let's copy the hat, and put it on a Cat sprite; this will exist our Mario. And we can re-create the cloud and put a few on a Blue Heaven properties for our background scenery.

Create a Mario game in Scratch for kids
Set up assets
Scratch coding for Mario game

2. Build the levels

Let's create a new sprite chosen 'Backgrounds'. Each costume will be some other level of our world, and we can create each level past copying and pasting pieces from our Avails backdrop. This is how to make a world in Mario Scratch games: get the edifice blocks put together in your assets section, and copy and rearrange them to build each level. You can build equally many levels every bit y'all want, merely we're using five for this tutorial.

Our Backgrounds sprite will be responsible for moving us through the world, and also telling our other sprites when they need to get in identify for each level. Each level volition have its own ? Blocks, Coins, and Enemies. We'll broadcast Delete Clones and Set Level to make certain everything resets correctly between levels. This will happen when the dark-green flag is clicked, and too when we go to the next Backgrounds costume.

Scratch backgrounds for Mario game
More backgrounds

3. Add together ? blocks

You may take noticed we left some space in between blocks when we created our levels. We're going to fill some of those in with ? Blocks. These blocks behave differently than normal background blocks, then they demand to be their ain sprite. When nosotros prepare a level, we're going to move our ? block sprite everywhere we want ane, and clone information technology. Where we move information technology depends on what level we're on.

In your project, for each level, elevate your ? Block sprite where you want it, and take note of its X and Y position. That's the position nosotros'll tell it to go to on that level, and clone itself. We'll use a strategy similar this to place our Coins and Enemies later besides.

Add question mark blocks
Programming Mario game in Scratch
Here's what it looks like in Scratch

4. Add detection sprites

In order to move Mario around our level, he needs to exist able to detect walls, floors, and ceilings. Nosotros shouldn't be able to go frontward if there's a pipage in front of u.s.a., or jump through a block. We can't just say, 'if touching Background, don't move'; if the front end of Mario is touching a wall, he can't move forwards, but he can still move backwards, and jump up.

We'll create four sprites, thin lines that follow Mario's location, and these sprites will let us know information virtually Mario'southward surround. Those sprites volition set variables that can tell united states if he's able to move right, left, up, or downwards. For example, if the 'Right' sprite is touching the 'Background' sprite, then we'll ready 'Right-Touching' to ane, and nosotros'll know Mario has something in front of him. If 'Correct-Touching' is 0, then Mario has nothing in forepart of him.

Fun Mario game in Scratch coding
Make a game with Scratch coding

v. Motility Mario with pointer keys

Mario should move Left and Right, be able to Jump when he's standing on something, and autumn down when there's nada below him. Nosotros'll use our detection variables to help united states out here. We too want Mario to be animated when he moves, and make sure he starts Level 1 standing in the right spot, facing the right direction.

If you're wondering how to make a scrolling platformer on Scratch, ane method is to move to the side by side level whenever the histrion sprite gets to the end of the previous ane. Nosotros do this past forever checking the Ten position of our sprite, and dissemination the 'Next Screen' bulletin when they touch the correct edge. Another method would be to brand the entire 'world' 1 big costume in the Backgrounds sprite, and motility the X position of that sprite to the left as our player moves forward. The latter method creates a cool result, just makes editing your game and adding to it much more complicated.

There's a lot of code here, and more to add later, so it'southward a good thought to utilize comments to assistance go on united states organized. You can add a comment to any code block by right clicking on it. Comments are extremely important when you have a lot of code, especially if it'southward complex. Comments should be short and descriptive. Fixing bugs in code will go a lot quicker if yous can rapidly see what clamper of lawmaking is responsible for what.

Coding a Mario game in Scratch

6. Add floating coins

Nosotros'll innovate a score variable now. In each level, permit's add together some floating coins, much in the same mode we added the ? Blocks. Paint a new sprite and create its costume past copying the Coin from our Assets backdrop. Nosotros'll move the sprite where it should be in that level, and create a clone of it. When that clone is created, we'll forever check and see if Mario touches it, and if he does, we can add a betoken to the score. Having them glide just a little bit up and down will create a nice floating animation.

Floating coins
Coding for floating coins
Here's how your Scratch Mario game should look now

7. Add ? block prizes

In the original Super Mario Bros, hit a ? Block could give you either a coin or a ability-up. We'll do something similar for our game. Most of the time, a ? Block will accept a coin that will add to our score, but sometimes, it volition have a star that we tin can pick upwards and go temporary invincibility from. Invincibility will protect us from the Enemies we'll add together later on, and we'll code that office in the next step.

Let'due south add code to our ? Block get-go. When Mario jumps into it, we'll switch its costume, move it upwardly and downwards a little, choose which prize to requite, and save the position of the cake. The ?-Block-10 and ?-Block-Y variables will exist responsible for telling our new Prize Star and Prize Coin sprites where to go.

Now we can create the Prize Star Sprite and Prize Money Sprite. When these sprites receive a bulletin, they'll go to the ? Block that was just striking and announced. If it's a money, it will disappear and add to the score. If it's a star, it volition expect for Mario to pick it up, and broadcast 'Invincible' when he does.

Add prize blocks
Prize blocks
Add ? block prizes

viii. Add together invincibility

We're broadcasting an 'Invincible' message whenever the Prize Star touches Mario. Let's take Mario reply to that bulletin at present. The primary thing nosotros want to do is set the 'Invincible' variable. We'll besides have Mario change color to bespeak that he's invulnerable from enemies. This will last for 5 seconds, and so nosotros'll set the 'Invincible' variable back to 0. We'll besides make sure to set 'Invincible' to 0 when we click the green flag. (Note: we're besides setting 'Score' to 0 here).

Add invincibility

Now it'due south time to add the enemies! We'll have iii in total for this tutorial, and they'll each comport a little differently, so we'll create a new sprite for each, and add them one at a time. Feel free to draw your ain Enemies (add them to the Assets backdrop!), simply we'll use regular Scratch sprites for this tutorial.

Nosotros'll add together our enemies to each level but like we've added ? Blocks, and Floating Coins, but since no level will have more than one of each type of enemy, we won't need to use clones. Whenever nosotros place an enemy, we'll likewise give it a path, or 2 spots information technology should glide dorsum and forth to. Each enemy will likewise check to encounter if Mario is invincible when they impact him; if he is, we'll send them flight off the screen. If he's not invincible, then Mario might lose when he touches an Enemy, simply we'll put that lawmaking in Mario's sprite afterwards.

ix. Add together first enemy (Hedgehog)

The Hedgehog enemy is small, but certainly to be avoided. We'll add a Hedgehog to Levels two, three, and 5. If Mario ever touches a Hedgehog when not invincible, it's game over.

Add an enemy
Hedgehog in Scratch game

10. Add 2nd enemy (Dinosaur)

The Dinosaur is much larger than the Hedgehog, just also a bit clumsier. Mario will really be able to defeat this enemy by jumping on its caput, even if he's not invincible, merely but if the Dinosaur isn't baring its jaws. Nosotros'll check this by seeing if the Bottom detection sprite is touching, if Mario is above the Dinosaur, and if the Dinosaur'south Costume Number is less than iv. The Dinosaur enemy will be present in Levels 3 and 5.

add dinosaur
Dinosaur in Scratch

eleven. Add together Tertiary Enemy (Parrot)

The Parrot is arguably the most dangerous enemy; information technology will actually throw eggs at Mario equally he navigates the level! The Egg will be a separate sprite, and when the Parrot sends the message, 'Throw Egg', it will repeatedly go to the Parrot and glide across the screen. The Parrot will only be nowadays on level 4 of our game.

Level 4 of Scratch game
Add to game
Game in Scratch coding

12. Check for lose

Now that we accept all of our Enemies coded, nosotros need to write code that checks to see if Mario is touching them (when he'due south non invincible). If he touches Enemy one, or Enemy two while its costume equals 4, or Enemy 3 or the Egg, we'll broadcast a 'game over' bulletin, end the code in Mario'south sprite, and hide Mario. You might notice that we're doing the same thing in all three of our If-Then blocks. Why non just do one actually big If-Then block? Sometimes it's better to write more than lawmaking if it makes the lawmaking easier to read and easier to alter. There's no point in having less code in our projection if that code is harder to deal with!

Another fashion of losing is if Mario falls off the bottom of the screen, so nosotros tin check for that likewise. We'll exercise the same thing nosotros did if Mario touches an enemy, minus the glide blocks.

Check for lose in Scratch coding

13. Bank check for Win

Let's create ii new sprites, a Victory Flag sprite, and a Win sprite. The Victory Flag will sit at the finish of Level 5, and nosotros'll identify it there merely like we did the Enemies, with the 'Gear up Level' message and a 'Get To X,Y' block. When Mario touches this flag, we'll circulate the 'Win' message, and show the Win sprite, along with the score.

Check for win
Win in Scratch coding

14. Add background music

At present information technology's time to add music in Scratch! Our game is about complete; the last finishing touch will be some more sounds. For a classic feel, you can upload a Super Mario Bros sound file for the background music, but we'll just use a congenital-in Scratch sound for this tutorial, Video Game 1. We'll also need background music for Mario'due south Invincibility, and a audio effect for losing and winning. Whenever we play a new sound, nosotros desire to finish the other sound that's already playing with a 'Terminate Other Scripts in this Sprite' block. Nosotros'll add another broadcast to Mario's code to start the regular music once more when his invincibility is over.

Add music
Background music in Scratch coding

Get started creating a Mario Game on Scratch

And in that location we have it, our very ain Mario Game in Scratch! More importantly, we have the beginnings of a useful game engine to make any sort of platformer in Scratch. Don't forget to upload and show off your projection here once y'all're done!

We tin easily build levels and worlds by taking pieces from our Assets backdrop and making new costumes in our Backgrounds sprite. We tin can add Enemies, and other interactive sprites to each level past hooking into the 'Set Level' bulletin, and placing those sprites with the 'Go To X,Y' block. What other things could nosotros add to this game? New enemies, new worlds?

If y'all liked building this game today, cheque out how to make a memory matching game in Scratch for an advanced tutorial using Lists and Define Blocks. And if you just love building games in Scratch generally, our Scratch Ninja course volition walk yous through some of the most essential techniques to building whatsoever sort of game you can think of!

Screen-Shot-2021-09-07-at-6.19.41-PM


Written past Ian Kuzmik, a Create & Learn instructor with a Bachelor's Degree in English language from Tulane University. He'due south been teaching grades K-8 since 2019, with a focus in the subjects of ESL and Computer Science.