Copyright 2017 MakeUseOf. All Rights Reserved.

Similar documents
Introduction to Turtle Art

Create Your Own World

In this project you ll learn how to create a platform game, in which you have to dodge the moving balls and reach the end of the level.

Game Making Workshop on Scratch

CONCEPTS EXPLAINED CONCEPTS (IN ORDER)

Scratch for Beginners Workbook

In this project you ll learn how to create a times table quiz, in which you have to get as many answers correct as you can in 30 seconds.

Lesson 8 Tic-Tac-Toe (Noughts and Crosses)

STEP-BY-STEP THINGS TO TRY FINISHED? START HERE NEW TO SCRATCH? CREATE YOUR FIRST SCRATCH PROJECT!

Create Your Own World

Create a game in which you have to guide a parrot through scrolling pipes to score points.

Rock Band. Introduction. Scratch. In this project you ll learn how to code your own musical instruments! Activity Checklist.

COMPUTING CURRICULUM TOOLKIT

Creating Computer Games

Alright! I can feel my limbs again! Magic star web! The Dark Wizard? Who are you again? Nice work! You ve broken the Dark Wizard s spell!

In this project you ll learn how to code your own musical instruments!

Lost in Space. Introduction. Scratch. You are going to learn how to program your own animation! Activity Checklist.

Ghostbusters. Level. Introduction:

2D Platform. Table of Contents

Scratch Programming Lesson 13. Mini Mario Game Part 4 Platforms

In this project, you will create a memory game where you have to memorise and repeat a sequence of random colours!

Cato s Hike Quick Start

a. the costumes tab and costumes panel

Annex IV - Stencyl Tutorial

1hr ACTIVITY GUIDE FOR FAMILIES. Hour of Code

Overview. The Game Idea

CISC 1600, Lab 2.2: More games in Scratch

AIM OF THE GAME GLACIER RACE. Glacier Race. Ben Gems: 20. Laura Gems: 13

Programming with Scratch

In this project we ll make our own version of the highly popular mobile game Flappy Bird. This project requires Scratch 2.0.

Tutorial: Creating maze games

Teaching Kids to Program. Lesson Plan: Interactive Holiday Card

Inspiring Creative Fun Ysbrydoledig Creadigol Hwyl. Kinect2Scratch Workbook

Lesson 2 Game Basics

Introducing Scratch Game development does not have to be difficult or expensive. The Lifelong Kindergarten Lab at Massachusetts Institute

G54GAM Lab Session 1

VACUUM MARAUDERS V1.0

Brain Game. Introduction. Scratch

GameSalad Basics. by J. Matthew Griffis

Scratch Coding And Geometry

Adding in 3D Models and Animations

Let s start by making a pencil, that can be used to draw on the stage.

Flappy Parrot Level 2

Let s start by making a pencil that can be used to draw on the stage.

The Beauty and Joy of Computing Lab Exercise 10: Shall we play a game? Objectives. Background (Pre-Lab Reading)

Space Invadersesque 2D shooter

Programming I (mblock)

Game Maker Tutorial Creating Maze Games Written by Mark Overmars

Create a Simple Game in Scratch

VERSION 3.0 WINDOWS USER GUIDE

Whack-a-Witch. Level. Activity Checklist Follow these INSTRUCTIONS one by one. Test Your Project Click on the green flag to TEST your code

An Introduction to ScratchJr

Learn Unity by Creating a 3D Multi-Level Platformer Game

The Joy of SVGs CUT ABOVE. pre training series 3. svg design Course. Jennifer Maker. CUT ABOVE SVG Design Course by Jennifer Maker

PHOTOSHOP PUZZLE EFFECT

Fireworks. Level. Introduction: In this project, we ll create a fireworks display over a city. Activity Checklist Follow these INSTRUCTIONS one by one

Blab Gallery Uploads: How to Reduce and/or Rotate Your Photo Last edited 11/20/2016

Starting from LEARNER NOTES edited version. An Introduction to Computing Science by Jeremy Scott

A. creating clones. Skills Training 5

Step 1 : Earth and Mars Orbit the Sun

GAME PROGRAMMING & DESIGN LAB 1 Egg Catcher - a simple SCRATCH game

Pong! The oldest commercially available game in history

Add in a new ghost sprite, and a suitable stage backdrop.

digitization station DIGITAL SCRAPBOOKING 120 West 14th Street

2809 CAD TRAINING: Part 1 Sketching and Making 3D Parts. Contents

Memory. Introduction. Scratch. In this project, you will create a memory game where you have to memorise and repeat a sequence of random colours!

TeamBoard Instructional Video Transcript Mecklenburg County Courthouse

Adding Content and Adjusting Layers

The Snipping Tool is automatically installed in Windows 7 and Windows 8.

ChatBot. Introduction. Scratch. You are going to learn how to program your own talking robot! Activity Checklist. Test your Project.

Lesson 1 Getting Started. 1. What are the different ways you interact with computers?

Tutorial: A scrolling shooter

Welcome to Weebly. Setting up Your Website. Write your username here:

Fish Chomp. Level. Activity Checklist Follow these INSTRUCTIONS one by one. Test Your Project Click on the green flag to TEST your code

CS Problem Solving and Structured Programming Lab 1 - Introduction to Programming in Alice designed by Barb Lerner Due: February 9/10

Star Defender. Section 1

Unit 6.5 Text Adventures

Photo Editing in Mac and ipad and iphone

04. Two Player Pong. 04.Two Player Pong

How to do automatic horizontal background scrolling in Scratch

Game Design Curriculum Multimedia Fusion 2. Created by Rahul Khurana. Copyright, VisionTech Camps & Classes

CREATING. Digital Animations. by Derek Breen

Next Back Save Project Save Project Save your Story

Project 1: Game of Bricks

Term Definition Introduced in: Tab(s) along the ribbon that show additional programs or features (e.g. Acrobat )

Videos get people excited, they get people educated and of course, they build trust that words on a page cannot do alone.

Getting Started Guide

pla<orm-style game which you can later add your own levels, powers and characters to. Feel free to improve on my art

Game Maker: Platform Game

Kodu Lesson 7 Game Design The game world Number of players The ultimate goal Game Rules and Objectives Point of View

A Quick Spin on Autodesk Revit Building

Pong Game. Intermediate. LPo v1

Welcome to JigsawBox!! How to Get Started Quickly...

Table of Contents. Creating Your First Project 4. Enhancing Your Slides 8. Adding Interactivity 12. Recording a Software Simulation 19

Getting Started. with Easy Blue Print

Introduction. The basics

Cricut Design Space App for ipad User Manual

In this project you ll learn how to create a game in which you have to save the Earth from space monsters.

In this project you ll learn how to create a game, in which you have to match up coloured dots with the correct part of the controller.

Chief Architect X3 Training Series. Layers and Layer Sets

Transcription:

Make Your Own Mario Game! Scratch Basics for Kids and Adults Written by Ben Stegner Published April 2017. Read the original article here: http://www.makeuseof.com/tag/make-mario-game-scratchbasics-kids-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.

Table of contents Meet Scratch 4 On-Screen Elements 5 Using Blocks 6 A Simple Example 8 Kicking the Ball 9 And the Crowd Goes Wild 9 Creating a Basic Mario Game 10 Import Graphics 10 Edit Sprite Costumes 10 Import Sounds 12 Animate the Coins 13 Making Mario Move 14 Animating the Ground 15 Mario s Logic 16 Collecting Coins 19 Scroll Coins and Clouds 19 Add Borders 21 Expanding Your Game 23

Did you know that anybody can make a video game without programming? Though there are several beginner-friendly languages, you don t have to spend half a year learning Java or C++ to build a game. You could choose from many tools for various types of games, but one great option for kids (and adults) is MIT s free Scratch. 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. Watch the YouTube video here: Scratch 2.0 Overview Video 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.

On-Screen Elements When you launch the editor, you ll see the below window. Let s break down its elements (see the full-size image if the small one below is unclear): 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. 1. Scripts is for adding blocks of code, which we ll cover soon. 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. 3. Sounds, unsurprisingly, is the center for adding and editing sounds. 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.

Using Blocks Now that you ve gotten acquainted with Scratch s editor, let s talk about one of the most important bits of the tool the code blocks. Instead of typing out real code, these blocks let you define the behavior of your elements. They snap together like LEGOs, making it easy to see how they affect each other.

Click a sprite from the list on the left and make sure to select the Scripts tab to start dragging blocks for that element. Note that the blocks are color-coded and have edges like a jigsaw puzzle to show how they fit together. The ten categories and what they do are: 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. Sound Play sounds, change volume, or adjust the tempo. 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! Control Loops to repeat an action, perform an if-else statement, or stop 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. More Blocks Make your own blocks if these aren t enough!

A Simple Example Let s take a simple example to illustrate how these blocks fit together, step by step. We ll make the Scratch cat kick a soccer ball into the goal, and play a sound when it goes in. 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

a fine time, and you ll need to click on the blue i icon of the soccer ball to see its coordinates. Enter those into the block, and your first action is complete! Kicking the Ball Once the cat touches the soccer ball, it should fly into the goal. So, select the soccer ball so you can add some actions to it. Remember that every action must start with an Event the green flag is fine for this instance. Now, you don t want the soccer ball to move until the cat touches it. Have a look at the Control category for a block that lets us limit its behavior. The Wait until block sounds about right! 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. And the Crowd Goes Wild The last step is adding sound! Select the Sounds tab above the work area to add a new one. Click the speaker icon under New sound to grab one from Scratch s library. There s one called Cheer under the Human category, which is perfect. Double-click it to add, then head back to the workspace for the soccer ball. 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.

Creating a Basic Mario Game The simple soccer example above shows how you can use blocks to control sprites, but it doesn t have any gameplay, animations, or music. Let s get more into it and create a simple Mario game. We could spend thousands of words on every aspect of making a game, so we ll stick to the basics. 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 running (two frames is sufficient for us) Mario jumping Animated coin Ground blocks Clouds Scratch has a Blue Sky 3 background, which will work fine for our needs. Edit Sprite Costumes Because there are two sprites that make up Mario s run animation, you need to add them as separate costumes. Use an image editor like Paint.NET to save the two Mario frames as separate files you can ignore the third. Upload the first Mario sprite, then select it and use the Costumes tab to upload the other sprite as his second costume. Give them distinguishable names, like Mario-1 and Mario-2. Add the jumping sprite as another costume for Mario.

Use an image editor to extract the cloud from the image provided above, then upload it as a new sprite. It s not animated, so you don t need to add a separate costume. 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.

You ll need to resize sprites using the Grow and Shrink buttons along the top of the screen, right above the green flag button. Click either button, then click the sprite you want to change on the stage to the left. This will resize all costumes, too. Ballpark them for now; you can finetune later. 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. Super Mario Bros. Theme Mario jump sound Coin collect sound

Animate the Coins Now that all of the assets are ready, it s time to start making them come alive. We ll start with the coins, since those are easy. Select the coin sprite and the Scripts tab. Since our coins are animated GIFs, we can use a series of blocks to constantly scroll through their costumes so they appear to move. An animation script looks something like this: 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.

Making Mario Move Now for the hard part. Many steps are involved in making Mario move, and it s actually a trick that scrolls the ground blocks to give the appearance of movement. Rather than try to explain every block loop, I ll provide screenshots of code blocks and explain their highlights. 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. OnGround keeps track of whether Mario is touching the ground or not. ScrollX measures the horizontal movement of the screen. Velocity (Mario only) controls the speed at which Mario jumps.

Animating the Ground You ve already made two duplicates of your Ground sprite by right-clicking it and choosing Duplicate. Drag Ground-1 to the far left of the screen, so its leftmost block touches the far left of the screen. Then, drag the other ground sprite(s) to the right of the first one. Line the edges up, and it will look like the ground is one solid piece. 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.

Mario s Logic That s all it takes for the blocks, but Mario has many more code blocks. Here s what each of them do, with a brief summary: 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.

Here we see the code that handles Mario s costume changes. When Mario is not on the ground, he has the jumping costume. Whenever you re moving left or right, Mario switches between frames every tenth of a second. Let go of the arrow keys, and Mario defaults to his standard frame. 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).

These two blocks of code handle Mario s jump velocity. On the left is a block that ensures Mario doesn t have any momentum if he s on the ground. If he s in the air, then his velocity is gradually slowed by gravity, which is a constant value. The right block makes Mario jump whenever you press the space bar. His jump sound plays, and the velocity propels him into the air until gravity takes over. 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.

Collecting Coins Let s jump back to the coins. We need to make sure that when Mario grabs one, it makes a sound and disappears. Let s make a separate script for that separating scripts by function is an important practice in programming. A big jumble of blocks makes it harder to figure out the problem when something goes wrong. Here s our coin collection script: 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. Scroll Coins and Clouds You re almost there! Since Mario doesn t move but the ground scrolls, we need to make sure that the coins scroll too so Mario can collect them. Here s how that works: 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.

The clouds use a nearly identical block of code: 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.

Add Borders Because of the way that we implemented the ground and coins, you ll see coins stuck at the edge of the screen until they scroll into view. This is unsightly, so you should create a quick border sprite that s the same color as the background to hide this on both the left and right sides.

The easiest way to do this is to right-click on the stage and click Save picture of stage. Open this in Paint.NET and use the pipette tool to select the blue background color. Add a new layer using the bottom-right dialogue. Then, use the rectangle tool to draw a filled blue rectangle on either side of the screen. Cover about a half of each block, then delete the background layer. 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:

Expanding Your Game Try out the final product below! 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.

Interested in taking this a step up? Check out Scratch For Arduino to build projects on that platform. If you re ready to dive in, check out everything you need to make an iphone game from scratch. 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! Read more stories like this at