how to make a mario game on scratch

"Create Your Own Mario Game: How-to Guide on Scratch"

By Nicole Davis
AD

Embarking on your first creation in the world of scratch, a popular block-based programming platform, can be an exciting journey. And what better way to kickstart it than by constructing your very own Mario game? Scratch, developed by MIT, is perfect for beginners, allowing you to easily create animations, games, and interactive art while learning programming concepts.

Today, we're going to guide you through creating a simple side-scrolling Mario game. By the end of this guide, you'll have a working game where Mario can move, jump, and interact with basic power-ups. Let's dive into the world of coding and pixel art!

Planning Your Mario Game

Before you start coding, let's plan your game. Scratch uses a 800x600 resolution, so make sure your design fits this space. Sketch out your game's layout on paper or use a digital tool to plan your levels, power-ups, and enemies.

AD
Make Your Own Mario Game! Scratch Basics for Kids and Adults
Make Your Own Mario Game! Scratch Basics for Kids and Adults
Make an Easy Mario Platformer Game on Scratch
Make an Easy Mario Platformer Game on Scratch
Scratch - Mario Tutorial - Adding in a Background
Scratch - Mario Tutorial - Adding in a Background

For this tutorial, we'll create a simple side-scrolling game with a single level consisting of platforms, a question block (to give Mario a power-up), and some enemies. Mario will be able to move left and right, jump, and gain a temporary speed boost from the question block.

Setting Up Your Scratch Project

First, head over to the Scratch website and create a new project. You'll see theScratch interface with a stage on the right and a blocks area on the left.

Scratch tutorial: how to make a Mario game
Scratch tutorial: how to make a Mario game
Make Your Own Mario Game! Scratch Basics for Kids and Adults
Make Your Own Mario Game! Scratch Basics for Kids and Adults

Before we add any code, let's prepare our stage. Add the sprites you'll need for your game. For this project, you'll need:

  • Mario: You can use the preloaded 'Costume1' sprite or upload your own sprites. We'll be using 'Costume1' for this tutorial.
  • Platforms: Create a new sprite and design your platforms using the painting tool.
  • Question Block: Create another sprite for the question block.
  • Enemy: Add an enemy sprite. For now, you can use the preloaded 'Alien1' sprite.

Designing Your Sprites

Use the painting tool (Paint tab) to add colors and create shapes for your platforms and question block. For the platforms, use a simple square or rectangle shape. For the question block, create a square with a question mark inside.

AD

You can also customize your Mario sprite by changing his costume or adding details. To switch costumes, click on the sprite, go to the Costumes tab, and choose a different costume or upload your own.

Setting the Stage

Arrange your sprites on the stage. Position Mario at the start of the level, place platforms in your planned layout, and add the question block and enemies where you want them.

Don't forget to hide theScratch logo (Stage) and grid (Stage, uncheck Show Grid), so your game looks clean. You can also adjust the stage size if needed, but keep the resolution to 800x600 for Scratch's optimal performance.

AD

Coding Your Mario Game

Now that your stage is set, it's time to add some code. We'll be using blocks from the Events, Motion, Looks, Sound, and Control categories. Start by adding the main game loop for Mario's movement.

Under Mario's scripts, click on the Events category and add the When Green Flag clicked block. Then, add a forever loop from the Control category to keep Mario moving continuously.

Mario's Movement

Inside the forever loop, add the following blocks to create Mario's sideways movement:

AD
  • Set velocity to x Velocity (Motion) to make Mario follow the last direction he was thrown.
  • If Space key pressed? (Events), then set y Velocity to -115 (Motion) to make Mario jump.

Add the code blocks for sideways movement by dragging the positive or negative blocks (Motion) into your script. Change the numbers to adjust the speed and direction. Here's the complete block layout:

Forever
Set velocity to x Velocity
If Space key pressed?
Set y Velocity to -115

Making Mario interactive

To make Mario interact with power-ups and enemies, we'll add collision detection. For this tutorial, we'll give Mario a temporary speed boost when he touches the question block.

Under Mario's scripts, add a new block and name it When I touch Question Block. In this block, add the following code:

  • Set x Velocity to 120 (Motion) to boost Mario's speed.
  • Hide the Question Block sprite (Looks) to remove it from the stage.

Add similar collision detection blocks for enemies, adjusting Mario's actions accordingly. You can also add code to handle game over scenarios, like Mario touching an enemy or falling off the stage.

Testing and Refining Your Game

With your game's core mechanics in place, test your game by clicking the green flag. Make sure Mario moves correctly, jumps, gains the speed boost, and interacts with objects.

Refine your game by adding more levels, enemies, power-ups, or a scoring system. You can also improve Mario's movements, add animations, and customize his appearance. The possibilities are endless!

Congratulations on creating your first Mario game on Scratch! Continue exploring and expanding your game design skills, and happy coding! Check out the completed project here for reference.

AD