Overview

Trash Panda is everyone's favorite button mashing, brick dodging, crow avoiding, building climbing, pizza snarfing raccoon game! OK, we just made it, so maybe it isn't everyone's favorite just yet, but we think soon it will be!

Learn to create your own exciting action game based on actual real-life events. You'll use MakeCode Arcade to craft the game, learning how to center the camera using null locators, spawn randomly timed obstacles, pizza power-ups, and set up button mashing input.

Get Lynn the Trash Panda to the top of the building as fast as you can to save the day!

Parts

Adafruit PyGamer Starter Kit

PRODUCT ID: 4277
Please note: you may get a royal blue or purple case with your starter kit (they're both lovely colors)What fits in your pocket, is fully Open...
OUT OF STOCK

Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino

PRODUCT ID: 4242
What fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right, it's the Adafruit...
OUT OF STOCK

Adafruit PyGamer Acrylic Enclosure Kit

PRODUCT ID: 4238
You've got your PyGamer, and you're ready to start jammin' on your favorite arcade games. You gaze adoringly at the charming silkscreen designed by Ada-friend...
$12.50
IN STOCK

Plastic Button Caps For Square Top (10-pack) - 8mm Diameter

PRODUCT ID: 4228
These Reese's Piece's lookin' bits fit perfectly on top of tactile buttons with 2.4mm square tops and give a satisfying 8mm diameter surface area for your fingers to...
$0.95
IN STOCK

Lithium Ion Polymer Battery with Short Cable - 3.7V 350mAh

PRODUCT ID: 4237
Lithium ion polymer (also known as 'lipo' or 'lipoly') batteries are thin, light and powerful. The output ranges from 4.2V when completely charged to 3.7V. This battery...
$5.95
IN STOCK

Mini Oval Speaker with Short Wires - 8 Ohm 1 Watt

PRODUCT ID: 4227
Hear the good news! This wee speaker is a great addition to any audio project where you need 8 ohm impedance and 1W or less of power. We particularly like...
OUT OF STOCK

Adafruit PyBadge for MakeCode Arcade, CircuitPython or Arduino

PRODUCT ID: 4200
Coming soon! Sign up to be notified when we have these in stockWhat's the size of a credit card and can run CircuitPython, MakeCode Arcade or Arduino? That's...
$34.95
IN STOCK

Adafruit PyBadge LC - MakeCode Arcade, CircuitPython or Arduino

PRODUCT ID: 3939
What's the size of a credit card and can run CircuitPython, MakeCode Arcade or Arduino even when you're on a budget? That's right, it's the Adafruit...
$24.95
IN STOCK

Pink and Purple Braided USB A to Micro B Cable - 2 meter long

PRODUCT ID: 4148
This cable is super-fashionable with a woven pink and purple Blinka-like pattern!First let's talk about the cover and over-molding. We got these in custom colors,...
$3.95
IN STOCK

Trash Panda Setup

MakeCode Arcade

If you're not already familiar with the basics of MakeCode Arcade, check out this guide on creating a character sprite and moving it with controls.

To start, open a new Chrome browser window (Chrome works best) and go to MakeCode Arcade beta.

These MakeCode Arcade guides are designed to take you through the fundamentals before tackling more complex games:

For intermediate-level techniques, check out:

Only use the Google Chrome browser with MakeCode!

Trash Panda

To begin with, let's load the finished version of MakeCode Arcade Trash Panda and try it out.

Start by launching MakeCode Arcade beta using the Google Chrome web browser. Then, download the arcade-TrashPanda.png file above by right-clicking on the image below and saving it to your computer.

Load the Code

This is a special .png file that contains not only an image, but the entire game is embedded in it as well!

Simply drag it from the location to which you saved the image on your computer (such as the desktop as shown here) onto the Chrome browser window that is already running MakeCode Arcade (MCA). Note that the image in this graphic is of a different game, but you'll be dragging the Trash Panda png file.

This will open the code into the MCA editor.

If you're ever unsure where a MakeCode block comes from, you can often find it by matching the block's color to a category on the left side of the editor. You can also use the handy search function!

Play It

Try out the game! As Lynn the Trash Panda, you need to mash the A or B button to climb the right or left side of the building. Avoid the falling bricks and flying crows -- they'll bump Lynn down the building a bit and she'll lose one heart!

If you see a delicious, huge slice of pizza one of the building dwellers has set on an open window sill, eat it! You'll gain one heart back.

Reach the top and you win the game -- the quicker you do so, the higher your score. This game is hard, so practice to get really good!

How it Works

Now, let's look at how it works. Some sections are similar to the previous games we've built, so we'll look at those only briefly, and got into more detail on the new techniques used.

On Start

In the on start block we'll first call the function named Intro. Here, we set the background image to act as a game title/splash screen.

Then, we call another function called bgm (background music) to loop four times with the repeat 4 times loop.

The bgm function contains the play tone and rest blocks of a startup song.

Next, we pause for a second and then give the player two screens of instructions using the show long text blocks, which must be advanced by pressing the A button.

Background and Tile Map

Next, we'll set background image to a city skyline, and then set tile map.

The tile map will act the same as a scrolling platformer map, except vertically rather than horizontally as we did in the Ruby platformer game.

Each index color block is used to place a different tile and in some cases will also be the spawn point for sprite characters, enemies, and food.

We'll look at these individual tiles in a moment.

Goal Setup

The goal is for Lynn to climb to the top of the building. We'll place sprites on some of the tile map positions to represent the UBS logo at the top of the building, as well as generic looking yellow and red building sprites that will be on the actual blocks the character needs to overlap to win.

Level Setup

In the levelSetup function we'll place the rest of the tiles. Have another look at the tile map to see where each of these images is being placed.

Lynn Character Setup

Now we'll set up the main character, Lynn the Trash Panda. This one is big, so we'll look at it in a few sections.

First, we'll create the Lynn character sprite and set her lives to 7, and then place her x/y position and z depth.

We'll have her appear on top of the blue tile on the tile map.

So that there is gravity in the scene for her to fight, we'll set Lynn ay (acceleration y) to 200.

 

Lynn Animation

Next up are Lynn's climbing animation and idle animation cycles. We'll create one set facing left (when she's on the right of the building) and one facing left.

We'll also set a single frame animation of Lynn when she's idle. This way we can switch between idle and climbing easily when the player is or isn't pressing one of the buttons.

Camera Nulls

The next thing we'll do is a bit tricky. We will need to trick the camera into following Lynn as she climbs the building, but not keep her in the center of the frame, which is the default behavior for the camera follow sprite block.

Instead, we want to center the camera with a 35 pixel offset to the left or right, depending on if she's on the right or left side of the building.

This will keep the building from seeming like it's jumping around the scene.

To do this, we'll create a pair of sprites to follow that we'll consider as transform nulls. They will be set to move with Lynn, but with their own relative offset on the x-axis.

These will be invisible during gameplay, but to help us visualize them and understand the concept, we'll create one set of them that have marker graphics, and another set that's invisible. By flipping the false to true in the if...else logic loop, we can turn on (or off) these visualization markers.

Pizza Time

It gets pretty tiring to climb a big, tall building when you're a sweet little trash panda. Thankfully, a thoughtful human will place a giant slice of pizza out of a randomly selected window for Lynn to eat!

In this function we'll set up the food, make a pizza slice sprite with a z depth of 1, and then use the place pizza on top of random white tile block to have it appear on one of the white tiles in the tile map.

Various Variables

These are the last few on start blocks to take care of. First, we'll set the center camera position. (Later the Lynn nulls will take care of this).

Then, we set up some variables for gameplay (we'll see how these are used momentarily:

  • dropBricks = true
  • sendCrows = true
  • goalMet = false
  • GameOn = true

activate animation Idle_Right on Lynn sets her in the ready position for game start.

Then, we'll set score to 1000 -- as the game progresses, this number will be counting down, so that the player's score is based on how quickly they reach the goal.

Trash Panda Game Play

Climbing Action

At heart, Trash Panda is a button mashing game! So let's set up some buttons to mash.

on A button pressed will be for climbing on the right side of the building and B on the left.

To prevent button presses during the splash screen from doing anything, such as playing unexpected sounds, we'll first check to see if the GameOn variable is true.

Then, we check to see if the goalMet variable is false. (This way, the buttons will stop working when Lynn reaches the top and the goalMet variable is flipped to true.)

The A button will move Lynn's horizontal (x) position to 180, and the B button to 110, which represent the two sides of the building.

Next, her velocity on y is set to -45, which is a boost in the vertical direction. Remember, we already set her acceleration on y to 200, so gravity will be constantly fighting against her. Press quickly to ascend! Her activate animation block will cause her to cycle through the climbing animation frames. Note the on game update block used to return her to Idle animation cycle when she isn't climbing in the y direction.

Now, we'll use our camera follow sprite block with the two offset nulls we created during the Lynn setup function. A button follows the Lynn_offset_Right null sprite and B the Lynn_offset_Left null sprite. Note the on game update block used to adjust the nulls to keep them in sync with Lynn's x position with offsets.

Lastly, we'll play a little two note climbing sound.

Pizza Power Up

When Lynn needs a power up, she can grab a slice! on sprite of kind Player overlaps otherSprite of kind Food will take care of noting when the collision occurs.

In this block we'll use destroy other Sprite with hearts effect for 500 ms to get rid of the pizza, change life by 1 to power up the hearts, and play sound ba ding until done.

Scoring

The faster Lynn makes it to the top, the higher the score! In order to calculate the score, we'll use on game update every 50 ms block.

It will first check that the goalMet variable is false.

Then, it will change scory by -1 point from the initial value of 1000.

Not only does this determine the score, but it's also a countdown timer! By adding the if score < 1 then ... game over lose blocks we can cause the game to end if the player takes too much time.

 

 

Bricks Keep Falling on My Head!

There are two kinds of enemies in Trash Panda -- falling bricks and flying crows. They work in nearly the same way, with a few adjustments. We'll look at the bricks first.

To begin with, on game update every pick random 600 to 1200 ms gives us a bit of variability to when bricks will fall.

Then, we check if dropBricks = true to see if the game has started and bricks are allowed to fall.

for element value of array of all pink tiles...do is a way of iterating through a list. In this case, there are three pink tiles in the tile map at the top of the level. The for element... block loops through those three tiles, one at a time.

Per element, the loop will do an if 10% chance then check, which randomizes the true/false check.

When the percent chance comes up true, we set brick to sprite of kind Enemy with a brick sprite graphic, and then on top of value place brick sets the sprite on top of the currently active element tile.

To drop the brick we set brick vy to 80, and we also set it to destroy on wall which is what happens if a brick reaches to bottom of the tile map where there is a row of tiles with the wall flag turned on.

Lastly, we'll play a descending tone glide from 1320hz to 440hz over the course of 800ms. This is a fancy looking block, because it doesn't yet exist in MakeCode Arcade's Block mode -- it was entered over in the JavaScript mode.

Crows Fly

We'll make the Crows just as we did the bricks. The main differences here are the tiles from which they spawn on either side of the board, and direction of travel, and the addition of a two frame animation cycle.

You can tune the feel of the gameplay by adjusting the timing and velocity of the various enemies. Try a lot of playtesting and adjusting of these, and get friends to help out!

I've Been Hit!

Here's what happens when Lynn collides with a brick or a crow:

  • on sprite of kind Enemy overlaps otherSprite of kind Player block senses the collision
  • change otherSprite y by 22 moves Lynn down the building a bit, so she looses progress and really needs to scramble to get to the top. Go Lynn!
  • change life by -1 removes one of the player's hearts
  • destroy sprite with rings effect for 200 ms gets rid of the brick or crow
  • camera shake by 5 pixels for 350 ms gives the player a good, jolting sense of a strong impact

Reaching Goals

The final element of the game is to determine what happens when Lynn reaches to top of the UBS building!

on sprite of kind Player overlaps otherSprite of kind Goal Lastly, we'll play a little two note climbing sound is the block that will check for that collision.

  • First, we'll flip the goalMet variable to true. Based on our previous setup, this will disable the buttons and stop the scoring from counting down anymore
  • We'll set Lynn to her Idle pose, and set acceleration y and velocity y to 0 so she stops moving
  • set dropBricks to false prevents new brick from spawning

Now, let's get on with some celebration!

  • play sound magic wand until done
  • show animation theatre chase for 2000 ms comes from the Light extension and will light up a pattern on the PyGamer or PyBadge NeoPixel strip!
  • use repeat block to flash the keyLogo from red to white four times, landing on red.
  • game over ... WIN!

 

Update the PyBadge/PyGamer Bootloader

You are at the bleeding edge of handheld, open source, game playing hardware and software, what with your PyBadge/PyBadge LC or PyGamer! Congratulations! It's fun and exciting! It is also changing and improving all the time, so please update your bootloaders before proceeding to put your MakeCode Arcade games on the board!!

Among lots of other reasons, update the bootloader to prevent a problem with MacOS 10.14.4, to fix button problems, and get the thumbstick to work!

PyBadge/PyBadge LC Bootloader

If you have a PyBadge or PyBadge LC, please go to this page for instructions on updating the bootloader.

A HUUUUUUGE number of people have problems because they pick a 'charge only' USB cable rather than a "Data/Sync" cable. Make 100% sure you have a good quality syncing cable. Srsly, I can't even express how many times people have nearly given up due to a flakey USB cable! Enter Alert Text...

Hardware Checks

If, after updating your board's bootloader, you still think you may have a hardware problem, here's a great way to test out all of the functions. From buttons, to the light sensor, thumbstick (PyGamer only), accelerometer (PyGamer and PyBadge only, not the LC), and more, we've got a super nifty set of hardware test .UF2 files you can use.

Click on the link for your board below for more info and a link to the appropriate UF2 file.

Another way to do a hardware check is with the handy, dandy MakeCode Arcade Basic Hardware Test. This was created with MakeCode Arcade and you can use it to check that your d-pad buttons or thumb joystick can move the yellow face around the screen, and that the A and B buttons work to play a sound (just make sure you have a speaker plugged in to the PyGamer first).

You can open this link to get to it, or download the UF2 file below and drag it onto your board's USB drive in bootloader mode.

Load a MakeCode Game on PyGamer/PyBadge

Let's load a game! For example, here's a link to Run, Blinka, Run! To open the game in the MakeCode Arcade editor, first, click the share link below. This will allow you to play the game in the browser right away.

Then, click on the Show Code button in the upper left corner. The shows the code for the game, and by clicking the Edit button in the upper right corner, it'll open into the editor where you can upload it to your PyGamer/PyBadge.

Once you have a game working on the MakeCode Arcade web editor, it's time to download it and flash it onto your board.

Please only use the Google Chrome browser with MakeCode! It has WebUSB support and seems to work best

Board Definition

In order to load a game made in MakeCode Arcade onto the PyBadge, first choose the proper board definition inside of MakeCode. Click the gear icon and then the Change Board item.

Change Board screen


Click on the image of your board, either the PyBadge/PyBadge LC or the PyGamer

This will cause the game .uf2 file for your particular board to be saved to your hard drive. You only need to do this the first time you use a new board. Thereafter you can simply click the Download button on the MakeCode Arcade editor page.

A HUUUUUUGE number of people have problems because they pick a 'charge only' USB cable rather than a "Data/Sync" cable. Make 100% sure you have a good quality syncing cable. Srsly, I can't even express how many times people have nearly given up due to a flakey USB cable!

Bootloader Mode

Now, we'll put the board into bootloader mode so we can drag on the saved .uf2 file. On the back side of the board you'll see a reset button at the top. Make sure the board is plugged into your computer via USB with a USB micro B to A data cable. Also, be sure the board is turned on.

 

Then, press the reset button. This will initiate bootloader mode.

 

When the board is in bootloader mode you'll see a screen similar to this one show up.

Drag and Drop

Now that the board is in bootloader mode, you should see a BADGEBOOT drive show up on your computer as a USB flash drive. Simply drag the arcade game .uf2 file onto the drive.

Play!

That's all there is to it! Once the file is copied over the board will restart and launch the game!

Keep an eye on Adafruit.com for additional game related content.

Troubleshooting MakeCode Arcade

If you run into trouble with MakeCode Arcade, here are some resources for getting help:

Only use the Google Chrome browser with MakeCode!
This guide was first published on Jun 15, 2019. It was last updated on Jun 15, 2019.