Exploring Makey Makey and MakeCode Arcade
CADDigital LiteracyComputing SystemsNetworks and the Internet

Exploring Makey Makey and MakeCode Arcade

Grades 4–12
2 hr 15 min
4 steps
Groups of 5
NC SCOS

Standards Alignment

NC SCOS

Computer Science

  • 68-CS-02: Design projects that combine hardware and software components to collect and exchange data.
  • 68-AP-03: Design and iteratively develop programs that combine control structures including nested loops and compound conditionals.
  • 68-DA-02: Collect data using computational tools.
  • 68-AP-06: Explain the design, implementation, and review of programs.
  • 68-AP-02: Create clearly named variables that represent different data types.
  • HS-AP-08: Create computational artifacts with pre-existing procedures, external components, libraries and APIs.
  • HS-AP-09: Create a computational artifact through an industry-standard process.
  • 68-AP-04: Construct programs that include events.
  • 68-AP-10: Systematically test and refine programs using a range of test cases.

Lesson Steps

1

Getting Started with Microsoft MakeCode Arcade

30 min

If you have never used Microsoft MakeCode before, it is a wonderful tool to start learning how to code. Originally developed and released as a programming platform for the BBC micro:bit several years ago, it has now expanded to include several other platforms in the hardware and software space. Let’s start with the MakeCode version called MakeCode Arcade, a game development platform for you to create your own old-school style video games! With Makey Makey, you can invent your own controllers for the games you code!

 

Supplies:

 

 

1. Welcome to MakeCode Arcade

In this getting started guide, you will walk through creating a new game in MakeCode Arcade, including navigating the environment, adding the Makey Makey code extension, and creating a simple “Hello World” program to move a character around the screen with Makey Makey.

 

 

2. Get Acquainted with MakeCode Arcade

MakeCode Arcade is a block-based programming environment similar to Scratch or Blockly where you “snap” or place different code blocks together to build a program and, in this case, a game. Navigate to arcade.makecode.com click on ‘New Project’ and give your game a quick name. You should now be on a window similar to the image below. Let’s get oriented to the MakeCode programming environment where you will be programming and building your games. 

 

 

(1)The main focus of the window is taken up by your programming space where you assemble your game code.

(2)You can find all  the code blocks you need to build a game in color-coded and sorted drawers . These drawers are themed around the functionality of the programming blocks they hold. Microsoft has also color-coded the blocks to make it easier to find things.

Quick Tip: If you ever have difficulty finding a block you are looking for, you can always use the search box at the top of the block drawers! 

(3)When you start to build your game, it will be previewed in the simulator window where you can test the game out by clicking on the controls or using keyboard controls. In our case, you will be using a Makey Makey rather than a keyboard and mouse.

(4)You can save your work by naming the file and clicking Save. This will download the file to your computer, but it will also save the game to the cookies on your computer in case you want to work on it later.

(5) When you get to the point of wanting to share your game for others to play, you can use the share button and choose from a number of ways to share your game with others, embed it in a website or blog, or even add it to a MakeCode Arcade Kiosk (more on that later!) 

(6) Finally, as you build your skill and understanding of coding you can switch between the drag and drop blocks and different text-based languages (javascript or Python) for some advanced programming options.

 

 

3. Let's Start Programming

 As a first program, you will create a basic demo level of a game and a character that can move around with the controls. 

 

 

First, you need to create the game's setting by adding a background. When you create a new program, your programming space starts with an on start block. Any code blocks you place inside of that block will execute or run at the start of your game. So, the first thing we do will be to add a set background color to ___ block inside of the on start block. 

 


 

You can find the set background color block under the scene drawer. Click and drag the block into the on start block. If the volume is turned up on your computer, it should snap into place with a satisfying clicking noise. 

 


 

From there, you can select a color of the background you want by clicking on the color swatch inside of set background color to ___. Once you choose a color, your simulator window should change to that color. 

Now, to add a character! With the background color set, it is time to place a character for us to control on the screen. 

 

 

You do this by opening the Sprites drawer and dragging in a set mySprite to____ block into your programming space and inserting it into the on start just below the background block. After placing the block, select an image for your sprite. Click on the swatch just inside of the blue sprite block opening up a sprite editor.

 

 

In MakeCode you can draw your own characters, but for this example, you will select an existing image from the gallery by selecting the “Gallery” tab at the top; feel free to choose any sprite you want from the list!

 

 

When you return to your programming window, you should see an updated simulator with your character in the center of the window. Now you have a character but no way of controlling it! This is because you haven’t programmed the character to move yet. A computer is only as smart as its programmer. Let’s make this game a little smarter! 

To enable controlling a sprite with your computer's keyboard keys (or the simulator buttons), you need to add the move mySprite with Buttons block from the Controller drawer. 

 

 

This block will enable you to move the selected sprite with the controller buttons and keyboard arrow keys, or even better… a Makey Makey! You should now be able to go over to the simulator with your mouse and hover over the window to bring it to focus. Press the arrow keys on your computer keyboard to see if your character moves around. 

Your final MakeCode Arcade program should look something like the above screenshot!

 

 

4. Plug and Play with Makey Makey

Using your USB cable, plug the Makey Makey into your computer's USB Port. It is ready to use once the Makey Makey has gone through its blinky cycle. Since Makey Makey works by completing a circuit, touch EARTH with one finger and then touch the right arrow key with another finger. Make sure to press them at the same time.   

 

 

Touching EARTH and an arrow key input  should complete the circuit between the two pads, and your character should move in the direction of the arrow key you pressed!

If your character doesn’t move for some reason, here are some troubleshooting tips:

  1. Check your connections from the Makey Makey to the computer. Make sure your USB cable is plugged into both!
  2. Does the LED by the Arrow Key input on the Makey Makey light up when you press the input? If not, ensure you complete a firm connection between the Arrow Key input and EARTH
  3. Is your simulator in focus? Make sure you mouse over the simulator and make sure it is in focus. You can tell it is in focus if the dpad is active. When the simulator is inactive, the controls are blued out. 

 

Inactive controller

 

 

5. Adding the Makey Makey MakeCode Extension

Many games are simple enough to use Makey Makey with just the move with buttons block. However, you will quickly find that you want to use other buttons in MakeCode, like the A and B buttons. These buttons are not mapped to the Makey Makey natively, there is a MakeCode extension to make the Makey Makey fully functional with MakeCode arcade for both single-player games and more elaborate two-player games. 

Adding the Makey Makey extension to your MakeCode Arcade games is pretty straightforward. Once you have created a game, it is just a few clicks away!

 


 

To add the extension, click on the Extensions drawer, which will open up a selection of community extensions that enable you to add different packages of blocks to your program. 

 

 

In the search bar, type “Makey Makey” and it will bring up our extension. Click on it to load it into your project. 

 


 

Once the extension loads, you will have a Makey Makey drawer with coding blocks specific to Makey Makey. Click on the Makey Makey drawer to see the Makey Makey coding  blocks! 

 


 

The first block maps the Makey Makey keys to the MakeCode Arcade keys (mapping A and B buttons to SPACE and CLICK on your Makey Makey). This will be one of your new favorite coding blocks! All you have to do is to add this block to the top of your on start event block in any program. This block will make  Makey Makey work for all the MakeCode Arcade buttons right out of the box.

The second block is a more in-depth block to map the different inputs on the Makey Makey to other controls for different players. You will use this in the case of a multiplayer game or if you want to use different inputs for player 1 in a single-player game. If you would prefer to control your sprite with WASD rather than the arrow keys, this block is what you would use to do that. We will incorporate this block into more advanced games in our How-to series!

 

Where to go now? 

Now that you have the basics of building and playing games in Microsoft MakeCode Arcade, it is recommended you check out the series of project How-To guides! They will walk you through how to program different games and recommend controllers to explore with Makey Makey to control those games! To get started, check out the first game in the series - Tag!

 

 

2

MakeCode Arcade Lesson One: Coding Sprite Movement with Classic Tag Game

30 min

In this project, you will build a basic tag game for the first real game with Microsoft MakeCode Arcade. In the introduction, you created a character or ‘sprite’, and were able to move it around the screen using the arrow keys on the keyboard or with our Makey Makey. You will build on that concept and add another sprite that will follow/chase our player sprite. The game's goal will be to go as long as you can without getting tagged.

 

Supplies:

  • Makey Makey
  • Create your own Controller!

 

 

1. Setting the Scene for Your First Game

If this is your first time using Microsoft MakeCode be sure to start with the Introduction to MakeCode Arcade with Makey Makey for a brief introduction to the environment and using Makey Makey with MakeCode Arcade. 

 

 

First, create a new game in MakeCode and name it whatever you like, but for the example the game will be named ‘Tag.’ 

 

 

 

The best games tell a story, and the best stories have a great setting. So, you need to set the stage for the game and that is done through setting the background. In the introduction, you used background color; this time use a background image instead. 

 

 

From the Scene drawer, select the set background image to___ block. This block is similar to the background color block but enables you to use an image rather than just a color. Place the block at the top of your on start block and click on the swatch, then find a thumbnail image in the Gallery tab to choose your setting. 

 


 

Remember, you are telling a story here, and the background sets the mood and theme of that story. So choose wisely!

 

 

Once you select the background image of your choice, click Select, and you can edit it further if you want. Once finished, click done in the lower right corner. 

 

 

2. Create a Player Sprite

With the background selected, you now have to add the character you will control: the sprite. 


 

You can add a sprite by opening the Sprite drawer and adding the set mySprite to___ block, placing it just below the background block in the on start block as the image shows. 

The set mySprite to__ block is a valuable and powerful block; you will use it a lot in creating games in MakeCode, so take a moment to review it in more detail here. It has three components, each of which will help you as your games get more complex. Let’s dive in and see what these components are.


 

First off, your sprite has a name! When you create a new sprite, MakeCode gives it a generic name of mySprite. If you were to create a new sprite, MakeCode would name it  mySprite2 and so on. This is just fine for simple games, but as you add more and more sprites, you may want to name them something more descriptive. You can create a custom sprite name by clicking on the drop-down next to the mySprite name and select rename variable and type in whatever name you would like!

 

 

Next up is the sprite image. You have experience with this already, so let’s select the image for your player sprite now! Remember to think about the story you are telling and to choose a sprite that would make sense for your game. 

 



Finally, your sprite has a kind! Think of the sprite kind as a way of sorting groups or categories of sprites. Think of your favorite video game. That game probably has enemies, something you collect to score, things to avoid, etc. Each of those things is a category or ‘type.’ MakeCode gives you some standard types, but you can also create your own, similar to naming your sprite. For this game, let’s leave your character as a Player type. 

 

 

3. Create an Enemy Sprite

Now, create a sprite for the character who is ‘it’! From the Sprite drawer bring in another set mySprite to ____ block and place it just below your first sprite. 

 


You can name your sprite if you would like, hopefully, something descriptive. Now, elect an image for your sprite and make sure to change change the kind type. The important thing is the difference in sprite type. You, you can create a custom type if you would prefer, but for this simple game, the kind type of ‘enemy’ works.

 

 

4. Set Location

Once you create your 2nd sprite, you will notice that both sprites start one on top of the other.


 

You need to change the starting location of the characters. First, the one who is it, by using the set Sprite position to x __ y __block. This block sets the x and y-coordinates' location of the sprite. Place the block as shown, select your ‘it’ sprite, and click on one of the numbers in the block. 

 

 

This will bring up a tool to let you choose the spot on the screen without having to guess the x and y-coordinates. 

 

 

Select the very top of the window. This tool then populates the correct X and Y coordinates for you. You should see your sprite move up to that position once the simulator runs.

 

 

If you want to start your player somewhere else on the screen, you would repeat the process: adding another location block, assigning it to that sprite, and selecting a spot. 

 

 

5. Controlling the Sprite

Now, to get things moving! You need to code movement for our player character that we want to control with the arrow keys, but you also want to code the  “it” sprite to chase your player. 

 

 

 

As in the getting started guide, you need to add the move mySprite with buttons block from the controls drawer to your program just below the set position blocks. You do not need to add anything other than this block to get your player sprite to move with basic controls. 

 

 

There is a handy block for getting the bad guy or the “it” sprite to chase you. It is called the set ____ to follow ____ block. This block tells one sprite to follow another sprite. That is perfect for a game of tag! The one issue is that the sprite doing the following will be really fast. To change the speed of the following sprite, click on the block's plus sign (+) and change the value to something lower; it is recommend starting at 50. 

 

 

Now, test your game! You should be able to move your player sprite around the window while the “it” sprite chases you. There is a problem, though. Nothing happens yet when the “it” sprite touches you because you need to write the program to tell the game what to do. 

 

6. When Sprites Collide

You can now program the tag functionality and tell MakeCode what to do when the two sprites touch each other.

 

Enter the on sprite of kind Player overlaps otherSprite of kind player block! This is an event block, meaning it will only run the code inside it when the given event trigger is true. In this case, when two different sprites overlap one another, it will trigger the event. For this first game, use this in its most simple form and add complexity to it in future games. Open the Sprites drawer, and you can find this block towards the bottom of the list under the Overlaps category. Drag it into your program. It should be on its own and shouldn’t fit into the on start block. The functionality of an event block is that it is its own little program inside of a program.

There is one change you need to make to this block, and that is to change the second sprite kind to an enemy kind of player, so the event will be triggered when one player sprite overlaps another sprite of the enemy kind. 

 

 

Now, what happens when you are tagged? In this game we want the game to be over! Find the game over ___ block from the Game drawer and drag it into the overlap event block. Now, change the state of the game over ___ block to lose.   

When you test your game, you should be able to run around and avoid the it sprite, but when it finally catches you, the game should end in a losing state!

  

 

7. Winning Scoring

But how do you win? That is a great question, and to be honest, the biggest issue with tag in general is that there isn’t really a winner!  

To be fair, you can add a game component of keeping score so you can compete against your friends. You will track how many seconds you can go without getting tagged and be rewarded with a score by incorporating another event block that will trigger scoring!

 

 

The event block you will use is called the on game update every _____ms block. This block is triggered in increments of time. You can find the block in the Game drawer. Click and drag one out into your program just below your on start event. Using the dropdown menu, change the value to 1 second (1000 milliseconds). Triggering this event every second!

 

 

Now, you want to change the score every second you aren’t tagged! From the Info drawer, find the change score by ____ block and drag that to the on game update every _____ms block. 

Now, when you test your game out, you should see a score counter in the upper right corner of your window, increasing each second that you are not tagged. When you are tagged, the Game Over window will show your final score! 

That is how you program tag in Microsoft MakeCode! For a full coding reference, you can check out the completed game below (check out the game in MakeCode here.)

 

Tag game simulator 

 

 

8. Recommended Controller and What's Next?

There are so many ways to incorporate a Makey Makey controller into this game. The one requirement is that it needs the four direction arrows for you to control your character’s movements: up, down, left, and right. A couple of controller options that are recommended are as follows. 

  1. Hula Hoop Controller
  2. Play-Doh Controller
  3. Glove Controller

Taking Your Game to the Next Level…

This game is rather simple and can get old quickly. It is designed to be a starting point for you to build from, not a finished product! You should try to take the game to the next level and add to it. Change it up and make it your own! A couple of ways you can explore how to do this…

 

  1. How does the “it” sprite get faster over time? 
  2. Does a sprite size change over time?
  3. How could you add lives as well as the score?

 Check out MakeCode Arcade Lesson Two: Collision and Scoring

 

3

MakeCode Arcade Lesson Two: Collision and Scoring with Fruit Catcher

30 min

This game is called Fruit Catcher, and it is a run-and-collect game. Fruit tokens fall from random points at the top of the screen, and the player controls a character to move back and forth and collects the fruit before it hits the ground. Let’s dig in and start catching fruit!

 

 

Supplies:

  • Makey Makey
  • Create your own Controller!

 

1. Setting the scene

 If this is your first time using Microsoft MakeCode, be sure to start with Introduction to MakeCode Arcade with Makey Makey for a brief introduction to the environment and using Makey Makey with MakeCode Arcade. 

 

 

Create a new game in MakeCode and name it whatever you like, but in the example the game is named ‘Fruit Catcher.’ 

 

 

You need to set the stage for our game, and that is done by setting the background. In the introduction, you used background color. For this game, you will use a background image instead. 

 

 

From the Scene drawer, select the set background image to ____ block. This block is similar to the background color block but enables you to use an image rather than just a color. Place the block at the top of your on start block and click on the swatch/thumbnail image in the block. 

 

 

This should bring up an editor window similar to the one you used to create a sprite. At the top of the window click on the Gallery tab and select the image of the tree/forest image. Remember, this game is called “Fruit Catcher,” and the fruit is falling from the trees, but if you want to change the theme from fruit, feel free!

 



Once you select the background image, click Select. If you want to edit the background you can do that in the editor. Once you are done editing and ready to code, click done in the lower right corner.

 

2. Set Player Sprite

With the background selected you can now add the character (the catcher) who will be the player character.

 


 

You will add a sprite by opening the Sprite drawer, adding the set mySprite to_____ block, and placing it just below the background block in the on start block as the image shows. 

The set mySprite to_____ block is a useful and powerful block, and you will use it a lot in creating games in MakeCode Arcade. You went over the details of the different parts of this block in our first game (Tag). If you need a quick refresh on these components, check out the sprite section in the Tag Coding guide. 


 

Let’s set the sprite image. You have experience with this already, so let’s select the image for your player sprite now! Remember to think about the story you are telling and to select a sprite that would make sense for your game. 


Finally, your sprite has a kind! For this game, the catcher is your player.  

 

3. Set Sprite Location and Move with Buttons

With your player sprite created, you now need to place the sprite in the correct position on the screen as well as program it to be able to move back and forth. 

 

 

From the Sprites drawer, drag the set mySprite location to x ___y ___  block and place it in your on start just below the set mySprite to ____  block. Make sure you select your player sprite name, and to set the location, click on either the X or Y number to bring up the location tool. Select somewhere at the bottom middle of the screen.

 

 

Now, apply controls to your character! Select the move mySprite with buttons block from the Controller drawer and drag it just below the sprite location block. Similar to the tag game, this block does a lot for you, but the main difference is that for this game, you only want the player character to move left and right and not up or down. To change that, click on the plus (+) sign on the block to open up the block details. This shows two velocity settings (vx and vy). Change vy to 0. Now your sprite will only move left and right, which means we’ve essentially turned the up and down movement off! 

 

 

The final block to add to your program regarding character movement is to keep your character sprite in the window and not run off to infinity! You can simply add a block from the Sprites drawer called set mySprite stay in screen block. This block does what it says and allows you to apply a rule to a sprite to stay in the screen with an on/off option. You want to set it to our character sprite and set the rule to ON. 

Test your game! Your character should be able to move back and forth, but not up and down.

 

4. Create Food Sprite and Code Velocity

With your player character dialed in and running back and forth, it is time to make the fruit fall for it to catch!

You need to repeat the process for creating the fruit sprite but in a different way. In your game, the fruit falls at a timed interval from a random location at the top of the screen. So, create multiple sprites, one every 500 milliseconds (half a second) or so. 

 


 

Enter the on game update every ___ ms event block. This event block is a timer, and the code inside is executed in increments of whatever time you set it to in milliseconds/seconds. Open the Game drawer and drag the block into your program area. The block’s standard timing is 500 milliseconds (half a second). Click on the drop-down and change it to 1 second!

 

 

You can now populate the event block with the required blocks to create our fruit sprite with an image of your choice and a player kind called food. This is similar to the player sprite and will be important later on!

 


 

Now let's learn the magic of creating the random starting location! You will be using the set mySprite location to x___ y___ block as you did with the player sprite, but will be coding the x and y values yourself rather than using the location picker tool. The Y value is easy; it should be something just barely on the screen in the Y direction, and a value of 5 works perfectly. But the X value takes a little more effort!

Use the pick random block to set a random X location for the fruit sprite. The pick random block accepts two values: a minimum and a maximum. This block, each time it is called or used, will produce a random number between those two values. It is recommended setting 10 as your minimum and 140 as your maximum. This way, all fruit will stay on the screen, but still offer a challenge for the player.

 


 

Finally, you need to make the fruit fall! You can add velocity to the fruit sprite using the set mySprite velocity to vx___ vy ___ block from the Sprites drawer. Drag it in and place it at the bottom of your on game update event block.  This block accepts two values: a velocity in the X direction (vx) and the Y direction (vy). You want to add velocity in the Y direction to simulate the fruit falling! Do this by setting vx to 0 and vy to 50.

Note: You can adjust your vy value as you see fit to make your game easier or more challenging!

 

 

Now, test your game! Your character should be able to move around (side to side), and fruit should start falling from the top of the screen. But, when you go to catch it nothing should happen! Why is that? Well, you haven’t programmed anything to happen yet… Let’s do that now!

  

5. When Sprites Collide!

To collect the fruit with your player, you need to add another event block that will be a foundation for future games you create. This event block is one that is triggered when two sprites overlap or collide!

 

 

Look for the on sprite of kind Player overlaps otherSprite of kind Player event block. This block resides inside the Sprites drawer under Overlaps. Drag it into your program. This block is an event block that executes code when two sprites of the specified kinds overlap!

This event block allows you to check the types or kinds of each sprite and trigger an event when these two types of sprites overlap or cross paths. In this game, we have two types. The first sprite is a Player kind and the second otherSprite sill be set to a Food kind. This event will only trigger when our Player sprite overlaps with a Fruit sprite and not when a Fruit sprite overlaps with another Fruit sprite. 

This event block also has what are called local variables. Local variables are the red sprite block and otherSprite blocks in the block's title. This enables you to work with just the two sprites that are actually colliding rather than all of the fruit sprites at the same time. Why would you want to do that? As an example, you want to destroy the fruit sprite that you overlap with and only that sprite, not all of the fruit in the window. 

 


 

So, from the Sprites drawer, drag in the destroy otherSprite block and place it inside of your on sprite of kind Player overlaps otherSprite of kind food event block. Now from the title of the event block drag in the red otherSprite block into the Destroy block. When this code is executed, it will only destroy the fruit that overlaps with our player (locally) and not destroy all of the fruit (globally). 

Test your game! You should be able to move back and forth and when you overlap a fruit it should disappear! 

 

6. Adding Timer and Scoring

The final step towards completing our Fruit Catcher game is to add two things… a time limit and scoring. These things are fairly simple and only require a single block to add that functionality!

 

 

 

For setting a time limit for your game, open the Info drawer and drag the start countdown__(s) block into the bottom of your on start event. This will allow you to start a countdown time at the start of the game that then ends the game when it reaches 0. Setting the countdown to 30 seconds feels like a good game length. However, you can change yours to whatever you want!

 


 

Finally, for scoring, we again open the Info drawer and drag the change score by ___ block into the overlap event, under the destroy otherSprite block. This will increase your score by whatever number you insert into this block. We kept it simple and just left it as 1. 

With that, your Fruit Catcher game is complete! Feel free to catch as much fruit as possible, modify the game to make it a little harder, and challenge your friends to catch as much fruit as they can! 

 

fruit catcher gif

 

That is how you program Fruit Catcher in Microsoft MakeCode! For a full reference of what code should look like, you can check out the full game and code in MakeCode here. 

 

 

7. Create a Controller and Next Steps

Recommended Makey Makey Controller

There are so many ways that you can incorporate a Makey Makey controller into this game. The one requirement is that it needs the four direction arrows for you to control your character’s movement: up, down, left, and right. A couple of controller options that we recommend are as follows. 

  1. Balance Ball Controller
  2. Tilt Controller
  3. Drawable Controller
 

Taking Your Game to the Next Level…

This game is rather simple and can get old quickly. It is designed to be a starting point for you to build from, not a finished product! Try to take the game to the next level and add to it. Change it up and make it your own! Here are some ideas to explore.

 
  1. Create different types of fruit that are worth different scores
  2. Create a 2nd player and see who can catch more fruit!
  3. Have the fruit randomly drop at different speeds
4

MakeCode Arcade Lesson Three: Variables and the Drag Race Challenge

45 min

This game is called Drag Race, and it is a 2-player button-mashing game where each player controls a car! The faster each player presses their assigned key, the faster their car goes. You will explore locations, simulating friction, and specific key event blocks. Let’s get your engines revving! 

 

Supplies:

  • Makey Makey

 

 

1. Programming the Game / Setting the Scene

If this is your first time using Microsoft MakeCode, be sure to start with Introduction to MakeCode Arcade with Makey Makey for a brief introduction to the environment and using Makey Makey with MakeCode Arcade. 

Create a new game in MakeCode called ‘Drag Race’ 

 

 

You need to set the stage for the game by setting the background. In the introduction, you used a background color. For this game, you will use a background image instead. 

 

 

From the Scene drawer, select the set background image to ____ block. This block is similar to the background color block but enables you to use an image rather than just a color. Place the block at the top of your on start block and click on the swatch/thumbnail image in the block. 

 

 

This should bring up an editor window similar to the one we used to create a sprite. At the top of the window, click on the Gallery tab and select the cityscape image. You are designing a car racing game, so the street background seems appropriate. You can take this game and modify the sprites and background later to create any other type of racing game!

 



Once you select the background image, click Select. If you want to edit the background, you can do that in the editor. For now, skip the editing and get to coding by clicking done in the lower right corner.

 

2. Create and Code Car Sprites

With the race location set, it is now time to create our contestants. This is a drag race game between two cars, so we must create two car sprites.

 

 

This part of creating sprites has been covered in detail in previous games. We will create two different sprites using the set mySprite to_____ block from the Sprites drawer (one for each). Name the sprites ‘Player1’ and ‘Player2’, and set them both to a ‘Player’ kind. 

 


 

MakeCode Arcade has several different colored car sprites in many different orientations. For this game, we will cars race from left to right on the screen, so we chose the cars facing the left!

 


 

Now, you need to set the starting location of the two cars. From the Sprites drawer, drag in two set mySprite position to x__  y__ blocks at the bottom of your on start block.  Use the location finder tool to set the X and Y coordinates for each sprite. Be sure to set the x coordinates to the same value to make it a fair race as that is the starting position! (Note: you covered the location finder tool in the last guide.)

 

 

3. Code speeding cars!

There are two cars in position, it is now time to get them moving! In previous games, you moved sprites using the simple move mySprite with buttons block. You will use a different block for this game!

 

 

You will use the on __ button pressed event block. This event block executes whatever code you insert into it rather than just moving the sprite with buttons. This block has two options; the first is what button it controls, and the second is the state of that button (pressed, released, repeated). 

 

 

You will need two of these blocks, one for each player. Player1 will use the left arrow key and Player2 will be attached to the right arrow key. Both states should be ‘pressed’. 

Th goal is to have either car be controlled and move when its matching on__ button pressed block is executed. To cause the cars (sprites) to move when the button is pressed, we use variables to track the “speed” of each car.

Variables in MakeCode are like a digital bucket; they hold things. In this case, variables hold numbers, and the number you want to hold in this project is the speed of each car. 

 

 

To create these variables open the Variables drawer. This drawer will be relatively empty until you fill it. Click on Make a Variable… and name your new variable ‘car1Speed’. This will be the variable that stores the speed of the Player1 car! Repeat the process and create a variable for ‘car2Speed’. 

 

 

Now, when you open the Variables drawer again, you should have some newly created blocks! The primary blocks that you will use when working with variables are blocks that set a variable (place something into that bucket) using the set __ to __  or you can change a variable in some way using the change __ by __ block. Both of these blocks are quite handy and you will use them to store information as you build more complicated games. 

 

 

You will also notice the rounded pill shape blocks as well. These blocks are the variables themselves. You will use these when you want to access and use their values. 

Now that you have two speed variables, you need to set both of those variables to 0 at the start of the game. From the Variables drawer, drag two set__to__ blocks into the on start event block. For each block set the variable option (one each for car1Speed and car2Speed) and their value both should be 0. 

 

 

With this variable now set to 0 at the start of the game, you can now manipulate or change them in our button press event blocks. 

 

 

From the Variables drawer, drag a change __ by __ block for each button press event block. For the on left button pressed block, select the ‘car1Speed’ variable and change it by a value of 3. This will add 3 to whatever value is currently stored in the variable. Repeat the process for the right arrow key and ‘car2Speed’. 

 

Before testing the game for the first time, you need to tell the cars to use the speed variables and move! Update the velocity of the two sprites every 100 milliseconds using the on game update every __ ms event block. 

 

 

From the Game drawer drag in an on game update every __ ms event and set the milliseconds value to 100. 

 

 

Inside the event block, update the speed of each car sprite. From the Sprites menu drag a set __ velocity to vx __ vy___ block in for each sprite. Be sure that each block is set to the different sprites as shown. Then from the Variables drawer drag in the ‘car1Speed’ variable and place it into the vx value for the player1 and repeat the process for the ‘car2Speed’ in the player2 set velocity block. 

 

 

You can now test your game! Start the game, and the more you press the left arrow, the faster the player1 sprite will go, and the more you press the right arrow, the faster the player2 sprite will go. 

 

 

4. Code Friction!

The cars move and you can race one another, but you may notice a few odd things. Primarily, the cars do not slow down when you stop pressing the buttons like they would in real life. When you take your foot off of the gas pedal, your car slows down. 

 

 

We can simulate the slowing down of the car by friction and gravity using an if statement to manipulate the speed variables. We want to use an if / else statement that uses the following logic:

“If the car is moving (speed greater than 1);  subtract 1 from the speed, else (the car is less than 1) set the speed to 0 (because you don’t want negative speed)” 

Let’s create this statement in blocks for one of the cars and you can test it out. 

 

 

From the Logic drawer, drag an if ____ then ___else ____ block and put it at the bottom of the on game update block. 

Now, create the comparison block to insert into the if statement. From the Logic drawer, drag a greater than (>) block into your if / else block.  

Next, from the Variables drawer, bring in the car1Speed variable and place it in the greater than block as shown. Change the other value to the number 1 and now the statement should read car1Speed > 1. 

If this statement is true, you want to subtract the value of 1 from the car1Speed variable using the change __ by __ block with car1Speed being changed by (-1). If the statement is false ( this would be the else section of the if statement) then you set the speed to 0 using the set car1Speed to 0 block as shown above. 

 

 

You should repeat the process for the car2Speed variable in a completely new if / else statement below the first one. Be sure that you are working with the car2Speed variable in it and not accidentally use the car1speed variable. 

 



Now the on game update every __ ms event should look like this and then test your game. Accelerate the cars by mashing on the arrow keys and then stop halfway through the race. The cars should slow down to a complete stop. Congrats, you have simulated gravity!

 

 

5. Create Winners!

Your cars now function like a car in the real world. But we still need to program winning and losing. It is a car race, there should be a finish line. So, let’s create one!

 


 

Let’s start by creating a finish line sprite! Drag a set __ to __ block from the Sprites drawer and insert it just below the other sprite block in the on start event block. Instead of selecting a pre-drawn sprite, create your own using the drawing tool!

 


 

First of all, the finish line is going to span the entire roadway, so the sprite needs to be much larger than the standard sprite size of 16 x 16 pixels. In the lower left hand corner you can change the image size in width and height. Change the dimensions to 4 x 120. The image should change size and shape. 

Keep things simple and go with a one-color finish line, you can get as fancy or elaborate as you want. Using the paint bucket tool from the toolbar and select a color of your choice from the options provided, the paint bucket tool will flood the image with color when you click on the object. Click the Done button. This creates a red stripe that you can now move around and use as a sprite and as the finish line. 

 


 

The final step here is to select a new kind from the sprite kind drop down menu and call it Goal. 

 

 

Now, place the finish line wherever you want, but the ideal location would be the far right side of the screen and spanning the roadway in the background. Drag a set__ position to __ x __y block from the Sprites drawer. Set the location using the tool to something to the far right side of the screen and spans in front of both cars. 

 


 

The final step is to program in what happens when a car overlaps with the finish line. You should se the on sprite of kind ___overlaps otherSprite of kind ____ event block. You can find it in the Sprites drawer and drag it into your program. Change the final kind option to Goal.

 


 

Place two blocks in the event block to broadcast the winner and both are found in the Game drawer. The first block is the use message____ for win block which will allow you to create custom messages for a win state at the end of the game! Drag it into your event block and add the text “WINNER!!!” as the message. Finally, drag the game over win block from the Game drawer and place it just below the message block. This will end the game and display the “WINNER!!!” message. 

 

 

Now, test your game! With any success, both cars should be able to drive and the first one to touch the finish line will win and trigger the Game Over screen! 

 


 

That is how you program Drag Race in Microsoft MakeCode! For a full reference of what code should look like, you can check out the completed game here!

 

 drag race

 

6. Create Controllers and Take it the Next Level

Recommended Makey Makey Controller

There are so many ways that you can incorporate a Makey Makey controller into this game. The one requirement is that you need one controllers for each player. Your game works with the direction arrows on Makey Makey: Left arrow input, and Right arrow input. A couple of controller options that we recommend are as follows. 

 

  1. Stomp switch
  2. Use people as a controller
  3. Slap switches

 

Taking Your Game to the Next Level…

This game is rather simple and can get old quickly. It is designed to be a starting point for you to build from, not a finished product! Try taking the game to the next level and add to it. Change it up and make it your own! Here are some ideas to explore.

 

  1. Customize your car with the sprite editor
  2. Create a nitro button to make your car faster for a second
  3. Create a hazard that slows your car down

Materials

  • Alligator Clip Pack — 140 per group
  • Connector Wires — 144 per group
  • Makey Makey Boards — 12 per classroom
  • Makey Makey Educator Guide — 1 per classroom
  • Makey Makey Special Pencils — 12 per group
  • USB Cables — 12 per group

Related Supply Kit

Makey Makey STEM Pack

All the hands-on materials you need for this lesson, delivered to your classroom.

Ready to bring this lesson to your classroom?

Sign up to save this lesson, order supplies, and track student progress.