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

'Platformer' refers to the mode a player must navigate obstacles in any given level of the game, often by literally jumping on platforms. And a truthful 'Side-Scroller' is divers past the way the histrion continuously reveals new parts of a level by moving their graphic symbol towards the right side of the screen.

Another common version of a Side-Scroller is one in which a level (or 'world,' to employ Mario terminology), is cleaved upward into parts, and to get to a new office, you must accomplish the end 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 starting time build a game 'engine'. The engine is sort of like the bare bones of the game; it determines graphics, and how sprites motion and collaborate.

Super Marios Bros 2 was released in 1988, but three years after the original. Nintendo didn't build a whole new game from scratch, they just expanded on the first game. They added new sprites and levels, some new features as well, but the gameplay was very like. With a good game engine, you can build endless games that volition all be fun and easy to build! Nosotros'll look at some strategies in this tutorial to make our Scratch coding game easy to build on.

If you lot're looking to improve your coding skills with a fun challenge, don't miss out on our fun Easter Scratch special i-60 minutes pocket-sized grouping course! To design even more cool games, join our gratuitous Scratch classes for kids:

How to make a Mario game on Scratch pace by footstep

To create our Mario game today, we'll be using a lot of dissemination and messaging, and a lot of X and Y positions. We'll also acquire some advanced techniques for creating platformers, and focus on keeping our game like shooting fish in a barrel to edit and add to. Hither's the Finished Project.

Yous can absolutely follow forth with this tutorial by creating your own Scratch project, only if this is your offset platformer, nosotros recommend remixing our Starter Projection, which has all of the Sprites and Costumes already put together and sized correctly. We'll even so need to write all the lawmaking though! (Note: if yous create your ain project, so the X and Y positions you apply in your code will probable demand to exist different than the ones used in this tutorial)

1. Ready assets

We're going to start building this game by getting our images and backgrounds in order. Permit's create a new backdrop called 'Assets'. We won't actually use this properties, but it will contain all of our custom drawings we'll employ for sprites and creating backgrounds. It will exist easier to build our game if we have everything in one place. Games that are built on the aforementioned game engine will oftentimes apply either the aforementioned assets, or very similar ones.

Once we have everything fatigued, let's copy the hat, and put it on a Cat sprite; this will be our Mario. And nosotros can copy the cloud and put a few on a Blue Sky backdrop for our background scenery.

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

ii. Build the levels

Permit'south create a new sprite chosen 'Backgrounds'. Each costume will be another level of our earth, and nosotros can create each level past copying and pasting pieces from our Avails backdrop. This is how to make a earth in Mario Scratch games: become the building blocks put together in your assets department, and copy and rearrange them to build each level. You lot can build as many levels equally you desire, simply we're using five for this tutorial.

Our Backgrounds sprite volition exist responsible for moving us through the globe, and also telling our other sprites when they need to go in place for each level. Each level will accept its own ? Blocks, Coins, and Enemies. Nosotros'll broadcast Delete Clones and Prepare Level to brand certain everything resets correctly betwixt levels. This will happen when the green flag is clicked, and besides when we become to the adjacent Backgrounds costume.

Scratch backgrounds for Mario game
More backgrounds

3. Add together ? blocks

You may have noticed we left some space in between blocks when we created our levels. Nosotros're going to fill some of those in with ? Blocks. These blocks behave differently than normal background blocks, and so they need to be their ain sprite. When we set a level, we're going to move our ? cake sprite everywhere we want i, and clone it. Where we move it depends on what level we're on.

In your project, for each level, drag your ? Block sprite where you lot want information technology, and have note of its Ten and Y position. That's the position we'll tell information technology to go to on that level, and clone itself. Nosotros'll apply a strategy like this to identify our Coins and Enemies later as well.

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 effectually our level, he needs to be able to detect walls, floors, and ceilings. We shouldn't be able to go forwards if in that location's a pipe in front of us, or spring through a block. We can't just say, 'if touching Background, don't move'; if the front of Mario is touching a wall, he can't motility forwards, but he tin 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 most Mario'due south surroundings. Those sprites will set variables that can tell us if he'southward able to move correct, left, up, or down. For example, if the 'Right' sprite is touching the 'Background' sprite, and then we'll set 'Right-Touching' to 1, and nosotros'll know Mario has something in front of him. If 'Right-Touching' is 0, so Mario has aught in front of him.

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

5. Motility Mario with arrow keys

Mario should movement Left and Correct, be able to Leap when he'southward standing on something, and autumn down when there'due south nothing below him. Nosotros'll use our detection variables to assistance us out here. We also want Mario to exist blithe when he moves, and brand sure he starts Level i standing in the correct spot, facing the right direction.

If you're wondering how to make a scrolling platformer on Scratch, one method is to move to the next level whenever the player sprite gets to the end of the previous one. Nosotros practise this by forever checking the X position of our sprite, and broadcasting the 'Next Screen' message when they touch the right edge. Some other method would be to make the entire 'world' one big costume in the Backgrounds sprite, and motility the Ten position of that sprite to the left as our player moves forrad. The latter method creates a cool effect, simply makes editing your game and adding to it much more than complicated.

At that place's a lot of code here, and more to add later, so information technology's a good idea to use comments to help keep united states organized. You tin can add a comment to whatever code block by right clicking on it. Comments are extremely important when y'all have a lot of lawmaking, especially if it'south circuitous. Comments should be short and descriptive. Fixing bugs in code volition get a lot quicker if y'all can quickly see what chunk of code is responsible for what.

Coding a Mario game in Scratch

half-dozen. Add floating coins

We'll introduce a score variable now. In each level, permit'south add some floating coins, much in the same way we added the ? Blocks. Pigment a new sprite and create its costume by copying the Coin from our Assets backdrop. We'll motility the sprite where information technology should be in that level, and create a clone of it. When that clone is created, we'll forever bank check and run into if Mario touches it, and if he does, we tin can add together a point to the score. Having them glide but a petty bit up and downwards volition 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 ? Cake could give you either a money or a power-up. We'll do something similar for our game. Nigh of the time, a ? Cake will have a money that will add to our score, just sometimes, it volition have a star that nosotros can choice upwardly and become temporary invincibility from. Invincibility will protect u.s.a. from the Enemies we'll add after, and we'll lawmaking that part in the adjacent step.

Let's add lawmaking to our ? Block first. When Mario jumps into information technology, we'll switch its costume, motility information technology upwards and down a niggling, choose which prize to give, and save the position of the block. The ?-Block-X and ?-Block-Y variables will be 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 message, they'll become to the ? Cake that was merely hit and appear. If information technology'southward a money, it will disappear and add to the score. If it's a star, information technology will wait for Mario to pick it up, and circulate 'Invincible' when he does.

Add prize blocks
Prize blocks
Add ? block prizes

viii. Add together invincibility

Nosotros're broadcasting an 'Invincible' message whenever the Prize Star touches Mario. Allow'due south have Mario answer to that bulletin now. The main thing we want to do is set the 'Invincible' variable. We'll also have Mario change color to betoken that he's invulnerable from enemies. This will last for five seconds, and and then we'll set up the 'Invincible' variable back to 0. Nosotros'll besides make sure to gear up 'Invincible' to 0 when we click the green flag. (Note: we're also setting 'Score' to 0 here).

Add invincibility

At present it's time to add the enemies! We'll have three in total for this tutorial, and they'll each behave a little differently, so we'll create a new sprite for each, and add them one at a time. Feel free to draw your own Enemies (add them to the Assets backdrop!), but we'll use regular Scratch sprites for this tutorial.

We'll add our enemies to each level only like we've added ? Blocks, and Floating Coins, simply since no level will have more than i of each type of enemy, we won't need to use clones. Whenever we place an enemy, we'll also give it a path, or 2 spots it should glide dorsum and forth to. Each enemy will also check to run into if Mario is invincible when they touch on him; if he is, we'll send them flying off the screen. If he's not invincible, then Mario might lose when he touches an Enemy, but nosotros'll put that code in Mario'due south sprite later.

nine. Add offset enemy (Hedgehog)

The Hedgehog enemy is small-scale, just certainly to exist avoided. We'll add a Hedgehog to Levels 2, 3, and 5. If Mario ever touches a Hedgehog when non invincible, it'due south game over.

Add an enemy
Hedgehog in Scratch game

x. Add second enemy (Dinosaur)

The Dinosaur is much larger than the Hedgehog, simply also a bit clumsier. Mario will actually be able to defeat this enemy by jumping on its head, even if he's not invincible, simply but if the Dinosaur isn't baring its jaws. Nosotros'll cheque 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 v.

add dinosaur
Dinosaur in Scratch

11. Add Third Enemy (Parrot)

The Parrot is arguably the most unsafe enemy; it will actually throw eggs at Mario every bit he navigates the level! The Egg will exist a separate sprite, and when the Parrot sends the message, 'Throw Egg', information technology will repeatedly go to the Parrot and glide beyond the screen. The Parrot will only be present on level iv of our game.

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

12. Check for lose

Now that we have all of our Enemies coded, we demand to write code that checks to come across if Mario is touching them (when he'southward not invincible). If he touches Enemy i, or Enemy 2 while its costume equals four, or Enemy 3 or the Egg, nosotros'll broadcast a 'game over' message, stop 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 not just exercise i really big If-Then block? Sometimes information technology'due south improve to write more code if it makes the code easier to read and easier to change. In that location's no signal in having less code in our projection if that code is harder to bargain with!

Another fashion of losing is if Mario falls off the lesser of the screen, so we can cheque for that as well. We'll do the same thing we did if Mario touches an enemy, minus the glide blocks.

Check for lose in Scratch coding

xiii. Bank check for Win

Permit'southward create two new sprites, a Victory Flag sprite, and a Win sprite. The Victory Flag volition sit down at the end of Level 5, and we'll identify it there just like we did the Enemies, with the 'Set Level' bulletin and a 'Get To X,Y' block. When Mario touches this flag, we'll broadcast the 'Win' message, and bear witness the Win sprite, forth with the score.

Check for win
Win in Scratch coding

14. Add background music

At present information technology's fourth dimension to add music in Scratch! Our game is almost consummate; the final finishing touch on will be some more sounds. For a classic feel, you can upload a Super Mario Bros sound file for the background music, only we'll just use a congenital-in Scratch sound for this tutorial, Video Game 1. We'll also need background music for Mario's Invincibility, and a audio issue for losing and winning. Whenever we play a new sound, we want to stop the other audio that's already playing with a 'Finish Other Scripts in this Sprite' block. Nosotros'll add another broadcast to Mario'south code to start the regular music again when his invincibility is over.

Add music
Background music in Scratch coding

Get started creating a Mario Game on Scratch

And there nosotros have it, our very ain Mario Game in Scratch! More importantly, we have the beginnings of a useful game engine to brand any sort of platformer in Scratch. Don't forget to upload and show off your project hither once yous're done!

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

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

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


Written by Ian Kuzmik, a Create & Learn instructor with a Available'south Caste in English from Tulane University. He's been instruction grades K-8 since 2019, with a focus in the subjects of ESL and Information science.