# Flappy Nyan Cat Game on Fruit Jam and Metro RP2350

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/135/701/medium800/gaming_flappy_nyan_hero.png?1741377254)

The Metro RP2350 makes a perfect little game console. The on-board HSTX combined with a DVI breakout can output to a standard television or computer monitor for the display. The broken out USB host connections make it easy to take input from a keyboard to control the game.&nbsp;

The Adafruit Fruit Jam simplifies setup even further by having the DVI connector and USB Host connectors directly on the board without the need to solder or connect any ribbon cables or additional breakouts.

This game features play inspired by flappy bird. As you fly, gravity pulls you down. You can press spacebar to jump and boost yourself back up. You must avoid the scratching posts and the top and bottom edges of the display. However, instead of a bird, you play as Nyan Cat leaving the iconic rainbow trail in your wake.

![](https://cdn-learn.adafruit.com/assets/assets/000/135/702/medium640thumb/gaming_flappy_nyancat_gameplay.jpg?1741377638)

## Parts
### Adafruit Fruit Jam - Mini RP2350 Computer

[Adafruit Fruit Jam - Mini RP2350 Computer](https://www.adafruit.com/product/6200)
We were catching up on a recent [hackaday hackchat with eben upton](https://hackaday.io/event/202122-raspberry-pi-hack-chat-with-eben-upton)&nbsp;and learned some fun facts: such as the DVI hack for the RP2040 was inspired by <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/6200)
[Related Guides to the Product](https://learn.adafruit.com/products/6200/guides)
![Angled shot of assembled mini computer PCB with plate.](https://cdn-shop.adafruit.com/640x480/6200-10.jpg)

### Adafruit Metro RP2350

[Adafruit Metro RP2350](https://www.adafruit.com/product/6003)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town". This train is piled high with hardware that complements the Raspberry Pi RP2350 chip to make it an excellent...

In Stock
[Buy Now](https://www.adafruit.com/product/6003)
[Related Guides to the Product](https://learn.adafruit.com/products/6003/guides)
![Angled shot of black, credit card-sized microcontroller with stacking headers.](https://cdn-shop.adafruit.com/640x480/6003-06.jpg)

Or

### Adafruit Metro RP2350 with PSRAM

[Adafruit Metro RP2350 with PSRAM](https://www.adafruit.com/product/6267)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town" and a bonus stop at "8 Megabytes of PSRAM village". This train is piled high with hardware that...

In Stock
[Buy Now](https://www.adafruit.com/product/6267)
[Related Guides to the Product](https://learn.adafruit.com/products/6267/guides)
![Angled shot of black, credit card-sized microcontroller.](https://cdn-shop.adafruit.com/640x480/6267-00.jpg)

### Adafruit RP2350 22-pin FPC HSTX to DVI Adapter for HDMI Displays

[Adafruit RP2350 22-pin FPC HSTX to DVI Adapter for HDMI Displays](https://www.adafruit.com/product/6055)
You may have noticed that our [RP2350 Feather](https://www.adafruit.com/product/6000) has an FPC output connector on the end&nbsp;for accessing the HSTX (High Speed Transmission)&nbsp;peripheral. This new capability, not available on the RP2040, is specifically designed to allow the...

In Stock
[Buy Now](https://www.adafruit.com/product/6055)
[Related Guides to the Product](https://learn.adafruit.com/products/6055/guides)
![black, square-shaped breakout board with DVI and 22-pin FPC connectors connected to a black, rectangular microcontroller.](https://cdn-shop.adafruit.com/640x480/6055-01.jpg)

### USB Type A Jack Breakout Cable with Premium Female Jumpers

[USB Type A Jack Breakout Cable with Premium Female Jumpers](https://www.adafruit.com/product/4449)
If you'd like to connect a USB-host-capable chip to your USB peripheral, this cable will make the task very simple.&nbsp; **There is no converter chip in this cable!** &nbsp;It's basically a plain USB cable that's cut in half and with jumper sockets on the power and data...

In Stock
[Buy Now](https://www.adafruit.com/product/4449)
[Related Guides to the Product](https://learn.adafruit.com/products/4449/guides)
![USB Type A Socket Breakout Cable with Premium Female Jumpers](https://cdn-shop.adafruit.com/640x480/4449-02.jpg)

### Break-away 0.1" 36-pin strip male header - Black - 10 pack

[Break-away 0.1" 36-pin strip male header - Black - 10 pack](https://www.adafruit.com/product/392)
Breakaway header is like the duct tape of electronics. It's great for connecting things together, soldering to perf-boards, fits into any breakout or breadboard, etc. We go through these guys real fast, and thought that given how handy they are, we'd offer them in a pack of ten!<br...></br...>

In Stock
[Buy Now](https://www.adafruit.com/product/392)
[Related Guides to the Product](https://learn.adafruit.com/products/392/guides)
![10 pieces of Break-away 0.1 inch 36-pin strip male header](https://cdn-shop.adafruit.com/640x480/392-01.jpg)

### 22-pin 0.5mm pitch FPC Flex Cable for DSI CSI or HSTX - 20cm

[22-pin 0.5mm pitch FPC Flex Cable for DSI CSI or HSTX - 20cm](https://www.adafruit.com/product/6036)
Connect this to that when a 22-pin FPC connector is needed. This 20 cm long cable is made of a flexible PCB. It's A-B style, meaning that pin one on one side will match with pin one on the other. How handy!

[We're stocking this to...](https://www.adafruit.com/category/360)

In Stock
[Buy Now](https://www.adafruit.com/product/6036)
[Related Guides to the Product](https://learn.adafruit.com/products/6036/guides)
![Angled shot of 20cm long, 22-pin FPC cable.](https://cdn-shop.adafruit.com/640x480/6036-00.jpg)

### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
![Angled shot of a coiled black, USB-C to USB-A cable.](https://cdn-shop.adafruit.com/640x480/4474-02.jpg)

# Flappy Nyan Cat Game on Fruit Jam and Metro RP2350

## Preparing the Metro RP2350

The USB Host port is the only part of this project that required soldering.

The USB Host pin connections are highlighted on the Metro image to the left. You will need a small piece of standard 0.1 inch male header, with 4 pins, to fit the holes.

You can cut header with diagonal cutters or break them with pliers or even your fingers. Just be sure to wear eye protection as they can fly when cut.&nbsp;

![Metro RP2350 with USB Host pins 5V, D-, D+, and GND highlighted. They sit between the main chip and the HSTX connector.](https://cdn-learn.adafruit.com/assets/assets/000/135/704/medium640/gaming_raspberry_pi_adafruit_products_pinouts_usbhost_highlight.png?1741378462)

![A row of 4 standard male header pins ready to be soldered to Metro](https://cdn-learn.adafruit.com/assets/assets/000/135/705/medium640/gaming_usb_host_pins.jpg?1741378510)

Put the short end of the header into the holes in the Metro marked USB Host and secure them with putty, blutack, tape, etc. Turn the Metro over and you should see the header barely poking out of the bottom of the board. If the pins stick through a great deal you may have the header pins upside down, double check the short end is sticking into the board.

Solder the 4 pin "nubbins" to the board.

![Metro RP2350 upside down next to HAKO soldering station](https://cdn-learn.adafruit.com/assets/assets/000/135/706/medium640/gaming_usb_host_soldering.jpeg?1741378603)

![Male header pins poking through the USB host pin holes on the Metro RP2350](https://cdn-learn.adafruit.com/assets/assets/000/135/707/medium640/gaming_usb_host_unsoldered.jpg?1741378690)

![Metro RP2350 upside down with USB Host pins soldered.](https://cdn-learn.adafruit.com/assets/assets/000/135/708/medium640/gaming_usb_host_soldered.jpg?1741378758)

Turn the board over and remove the material securing the pins. Now there is a new 4-pin header.&nbsp;

Get the USB Host cable and wire as follows:

**GRD** to **Black**

**D+** to **Green**

**D-** to **White**

**5V** to **Red**

![Metro RP2350 right side up with the USB Host male header pins soldered.](https://cdn-learn.adafruit.com/assets/assets/000/135/709/medium640/gaming_usb_host_pins_complete.jpg?1741378869)

![](https://cdn-learn.adafruit.com/assets/assets/000/135/710/medium800/gaming_usb_host_wire_attached.jpg?1741378939)

## HSTX Connection to DVI
![](https://cdn-learn.adafruit.com/assets/assets/000/135/711/medium800/gaming_hstx_breakout_ribbon_connected.png?1741378983)

Get the HSTX cable. Any length Adafruit sells is fine. CAREFULLY lift the dark grey bar up on the Metro, insert the cable silver side down, blue side up, then put the bar CAREFULLY down, ensuring it locks. If it feels like it doesn't want to go, do not force it.

Do the same with the other end and the DVI breakout. Note that the DVI breakout will be inverted/upside down when compared to the Metro - this is normal for these boards and the Adafruit cables.

# Flappy Nyan Cat Game on Fruit Jam and Metro RP2350

## Install CircuitPython Metro

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_metro_rp2350/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/655/medium640/install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg?1618943202)

![](https://cdn-learn.adafruit.com/assets/assets/000/135/292/medium800/adafruit_products_boot_reset_btn_highlights.png?1739467365)

To enter the bootloader, hold down the **BOOT/**** BOOTSEL button**(highlighted in red above), and while continuing to hold it (don't let go!), press and release the**reset button**(highlighted in red or blue above).&nbsp;**Continue to hold the BOOT/BOOTSEL button until the RP2350 drive appears!**

If the drive does not appear, release all the buttons, and then repeat the process above.

You can also start with your board unplugged from USB, press and hold the BOOTSEL button (highlighted in red above), continue to hold it while plugging it into USB, and wait for the drive to appear before releasing the button.

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

You will see a new disk drive appear called **RP2350**.

&nbsp;

Drag the **adafruit-circuitpython-_boardname_-_language_-_version_.uf2** file to **RP2350.**

![install_circuitpython_on_rp2350_Screenshot_2024-09-11_111518.png](https://cdn-learn.adafruit.com/assets/assets/000/132/253/medium640/install_circuitpython_on_rp2350_Screenshot_2024-09-11_111518.png?1726067809)

![install_circuitpython_on_rp2350_Screenshot_2024-09-11_111742.png](https://cdn-learn.adafruit.com/assets/assets/000/132/254/medium640/install_circuitpython_on_rp2350_Screenshot_2024-09-11_111742.png?1726067866)

The **RP2350** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it, you're done! :)

![install_circuitpython_on_rp2350_Screenshot_2024-09-11_111843.png](https://cdn-learn.adafruit.com/assets/assets/000/132/255/medium640/install_circuitpython_on_rp2350_Screenshot_2024-09-11_111843.png?1726067932)

## Safe Mode

You want to edit your **code.py** or modify the files on your **CIRCUITPY** drive, but find that you can't. Perhaps your board has gotten into a state where **CIRCUITPY** is read-only. You may have turned off the **CIRCUITPY** drive altogether. Whatever the reason, safe mode can help.

Safe mode in CircuitPython does not run any user code on startup, and disables auto-reload. This means a few things. First, safe mode _bypasses any code in_ **boot.py** (where you can set **CIRCUITPY** read-only or turn it off completely). Second, _it does not run the code in_ **code.py**. And finally, _it does not automatically soft-reload when data is written to the_ **CIRCUITPY** _drive_.

Therefore, whatever you may have done to put your board in a non-interactive state, safe mode gives you the opportunity to correct it without losing all of the data on the **CIRCUITPY** drive.

### Entering Safe Mode
To enter safe mode when using CircuitPython, plug in your board or hit reset (highlighted in red above). Immediately after the board starts up or resets, it waits 1000ms. On some boards, the onboard status LED (highlighted in green above) will blink yellow during that time. If you press reset during that 1000ms, the board will start up in safe mode. It can be difficult to react to the yellow LED, so you may want to think of it simply as a slow double click of the reset button. (Remember, a fast double click of reset enters the bootloader.)

### In Safe Mode

If you successfully enter safe mode on CircuitPython, the LED will intermittently blink yellow three times.

If you connect to the serial console, you'll find the following message.

```terminal
Auto-reload is off.
Running in safe mode! Not running saved code.

CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.
```

You can now edit the contents of the **CIRCUITPY** drive. Remember, _your code will not run until you press the reset button, or unplug and plug in your board, to get out of safe mode._

## Flash Resetting UF2

If your board ever gets into a really _weird_ state and CIRCUITPY doesn't show up as a disk drive after installing CircuitPython, try loading this 'nuke' UF2 to RP2350. which will do a 'deep clean' on your Flash Memory. **You will lose all the files on the board** , but at least you'll be able to revive it! After loading this UF2, follow the steps above to re-install CircuitPython.

[Download flash erasing "nuke" UF2 for RP2350](https://cdn-learn.adafruit.com/assets/assets/000/132/526/original/rp2350_flash_nuke.uf2)
# Flappy Nyan Cat Game on Fruit Jam and Metro RP2350

## Install CircuitPython Fruit Jam

[CircuitPython](https://github.com/adafruit/circuitpython) is a derivative of [MicroPython](https://micropython.org) designed to simplify experimentation and education on low-cost microcontrollers. It makes it easier than ever to get prototyping by requiring no upfront desktop software downloads. Simply copy and edit files on the **CIRCUITPY** drive to iterate.

## CircuitPython Quickstart

Follow this step-by-step to quickly get CircuitPython running on your board.

Warning: Please use the latest release of 10.x or higher for the Fruit Jam. Also use the latest libraries for the best functionality.

[Download the latest version of CircuitPython for this board via circuitpython.org](https://circuitpython.org/board/adafruit_fruit_jam/)
 **Click the link above to download the latest CircuitPython UF2 file.**

Save it wherever is convenient for you.

![install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg](https://cdn-learn.adafruit.com/assets/assets/000/101/655/medium640/install_circuitpython_on_rp2040_RP2040_UF2_downloaded.jpg?1618943202)

![reset and boot highlighted](https://cdn-learn.adafruit.com/assets/assets/000/138/708/medium800/adafruit_products_Resetboot.jpg?1754331128 )

To enter the bootloader, hold down the **BOOT/**** BOOTSEL button**(highlighted in red above), and while continuing to hold it (don't let go!), press and release the**reset button**(highlighted in red or blue above).&nbsp;**Continue to hold the BOOT/BOOTSEL button until the RP2350 drive appears!**

If the drive does not appear, release all the buttons, and then repeat the process above.

You can also start with your board unplugged from USB, press and hold the BOOTSEL button (highlighted in red above), continue to hold it while plugging it into USB, and wait for the drive to appear before releasing the button.

A lot of people end up using charge-only USB cables and it is very frustrating! **Make sure you have a USB cable you know is good for data sync.**

You will see a new disk drive appear called **RP2350**.

&nbsp;

Drag the **adafruit-circuitpython-_boardname_-_language_-_version_.uf2** file to **RP2350.**

![install_circuitpython_on_rp2350_Screenshot_2024-09-11_111518.png](https://cdn-learn.adafruit.com/assets/assets/000/132/253/medium640/install_circuitpython_on_rp2350_Screenshot_2024-09-11_111518.png?1726067809)

![install_circuitpython_on_rp2350_Screenshot_2024-09-11_111742.png](https://cdn-learn.adafruit.com/assets/assets/000/132/254/medium640/install_circuitpython_on_rp2350_Screenshot_2024-09-11_111742.png?1726067866)

The **RP2350** drive will disappear and a new disk drive called **CIRCUITPY** will appear.

That's it, you're done! :)

![install_circuitpython_on_rp2350_Screenshot_2024-09-11_111843.png](https://cdn-learn.adafruit.com/assets/assets/000/132/255/medium640/install_circuitpython_on_rp2350_Screenshot_2024-09-11_111843.png?1726067932)

## Safe Mode

You want to edit your **code.py** or modify the files on your **CIRCUITPY** drive, but find that you can't. Perhaps your board has gotten into a state where **CIRCUITPY** is read-only. You may have turned off the **CIRCUITPY** drive altogether. Whatever the reason, safe mode can help.

Safe mode in CircuitPython does not run any user code on startup, and disables auto-reload. This means a few things. First, safe mode _bypasses any code in_ **boot.py** (where you can set **CIRCUITPY** read-only or turn it off completely). Second, _it does not run the code in_ **code.py**. And finally, _it does not automatically soft-reload when data is written to the_ **CIRCUITPY** _drive_.

Therefore, whatever you may have done to put your board in a non-interactive state, safe mode gives you the opportunity to correct it without losing all of the data on the **CIRCUITPY** drive.

### Entering Safe Mode
To enter safe mode when using CircuitPython, plug in your board or hit reset (highlighted in red above). Immediately after the board starts up or resets, it waits 1000ms. On some boards, the onboard status LED (highlighted in green above) will blink yellow during that time. If you press reset during that 1000ms, the board will start up in safe mode. It can be difficult to react to the yellow LED, so you may want to think of it simply as a slow double click of the reset button. (Remember, a fast double click of reset enters the bootloader.)

### In Safe Mode

If you successfully enter safe mode on CircuitPython, the LED will intermittently blink yellow three times.

If you connect to the serial console, you'll find the following message.

```terminal
Auto-reload is off.
Running in safe mode! Not running saved code.

CircuitPython is in safe mode because you pressed the reset button during boot. Press again to exit safe mode.

Press any key to enter the REPL. Use CTRL-D to reload.
```

You can now edit the contents of the **CIRCUITPY** drive. Remember, _your code will not run until you press the reset button, or unplug and plug in your board, to get out of safe mode._

## Flash Resetting UF2

If your board ever gets into a really _weird_ state and CIRCUITPY doesn't show up as a disk drive after installing CircuitPython, try loading this 'nuke' UF2 to RP2350. which will do a 'deep clean' on your Flash Memory. **You will lose all the files on the board** , but at least you'll be able to revive it! After loading this UF2, follow the steps above to re-install CircuitPython.

[Download flash erasing "nuke" UF2 for RP2350](https://cdn-learn.adafruit.com/assets/assets/000/132/526/original/rp2350_flash_nuke.uf2)
# Flappy Nyan Cat Game on Fruit Jam and Metro RP2350

## Code

## CircuitPython Usage

To use the game, you need to update&nbsp; **code.py** with the game program&nbsp;to the **CIRCUITPY** drive.

Thankfully, we can do this in one go. In the example below, click the **Download Project Bundle** button below to download the necessary libraries and the **code.py** file in a zip file.

Connect your board to your computer via a known good data+power USB cable. The board should show up in your File Explorer/Finder (depending on your operating system) as a flash drive named **CIRCUITPY**.

Extract the contents of the zip file, copy the **lib** directory files to **CIRCUITPY/lib**. Copy the **code.py** file to your **CIRCUITPY** drive. The program should self start.

## Drive Structure

After copying the files, your drive should look like the listing below. It can contain other files as well, but must contain these at a minimum.

![Screenshot](https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/folder-images/Metro_Metro_RP2350_FlappyNyanCat.png?raw=true )

## Code

The **code.py** for the project is shown below.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/Metro/Metro_RP2350_FlappyNyanCat/code.py

# Flappy Nyan Cat Game on Fruit Jam and Metro RP2350

## Usage

Ensure a USB keyboard is plugged into the USB Host port wired up previously. Reset the board by cycling power or pressing the Reset button if you happen to plug in a keyboard after power up.

Be sure you connect the DVI breakout to an HDMI monitor and the monitor is on. You might need a long cable if your monitor is not near the Metro RP2350 (like a television). The cables are standard and may be obtained from any trusted retail outlet. Also reset the Metro if you plug in HDMI after powering the Metro.

Once connections are all set, power the Metro RP2350 either via USB C (5 volts) or the barrel connection (5.5 to 17 volts DC, center positive).

## Gameplay
![](https://cdn-learn.adafruit.com/assets/assets/000/135/700/medium800/gaming_flappy_nyan_hero.png?1741377143)

The controls for the game are as follows:

- **Spacebar** : Start the game, and make the cat jump.
- **S** : During play, press **S** to swap the trail between rainbow and trans flag colors.
- **P** : After game over, press **P** to play again.
- **Q** : After game over, press **Q** to quit.

![](https://cdn-learn.adafruit.com/assets/assets/000/135/699/medium800thumb/gaming_flappy_nyancat_gameplay.jpg?1741375832)

The goal is to keep the cat flying for as long as you can without running into either the scratching posts, or the edges of the screen. The player is awarded 1 point for each jump, 1 point each time the swap the trail colors, and 10 points for each set of posts that fly off the left edge of the screen. For every 100 points that are scored the flying speed gets faster making harder and harder to avoid the posts.

# Flappy Nyan Cat Game on Fruit Jam and Metro RP2350

## Code Explanation

The code for the game is thoroughly commented with explanations of what each line or section are for. This page will provide a higher level summary of the major components.

## Hardware Principals

This game is designed around two primary hardware peripherals: the HSTX connector with a DVI breakout for the display, and a basic USB keyboard for the player control input.

### HSTX Display

To initialize the display the built-in core modules `picodvi`, and&nbsp;`framebufferio` are used. These modules support a few different resolutions and color depths. This project is made for the 320x240 resolution with 16 bit color depth. The pixels are automatically doubled before being pushed to the display so it will come out as 640x480, depending on your monitor or TV, it may further upscale it to fit the screen.

### USB Keyboard

USB Host is relatively new to CircuitPython, first coming on Raspberry Pi RP2040-based boards.&nbsp;

Typically, one would access a USB port by:

- Establishing the USB connection
- Reading USB Reports, sections of bytes sent when an action occurs on the peripheral like a key is pressed or joystick moved.
- Parsing the reports and providing meaningful input to the program.

Python has the concept of standard input and output streams, similar to those in Linux/Unix and other operating systems. CircuitPython has this capability and through a lot of behind the scenes code, presents a USB keyboard as a stdin input device. The code to get USB Host Keyboard characters and echo them to serial out is as follows:

```auto
import supervisor
import sys

while True:
    available = supervisor.runtime.serial_bytes_available
    if available:
        c = sys.stdin.read(available)
        print(c, end='')
```

As an added bonus this also means that the game can be played via the USB Serial connection with your PC. Simply connect to your device with your preferred serial console application, make sure the app has focus and anything you type on your PC keyboard gets sent to CircuitPython via the same `stdin` stream it's reading keyboard keys from.

## Helper Classes

The game code has 3 helper classes which contain behavior for various parts of the game bundled together as easy to use component objects.

### `Post`

The `Post` class extends `displayio.Group` so it can contain `TileGrid`s and other visual elements to be shown on the display. While it's name is `Post`&nbsp;singular, it actually holds a pair of visual posts, one at the top of the screen, and the other at the bottom. In the original flappy bird, these were green pipes. The `check_collision()`&nbsp;function will determine if the cat sprite is colliding with either of the posts in this `Post` instance. These `Post` objects get moved along the screen by updating the `x` coordinate to lower values for each fame of the game.

### `PostPool`

`PostPool` is a "grab bag" of `Post`s to store the ones not currently in use, and provide one for us randomly when we need to add a new one to the right edge of the display. The `get_post()` and `recycle_post()` functions are used to get an unused `Post`, and then recycle it back into the pool when it's no longer needed.

### `GameOverException`

This is a basic custom exception that the code will raise when the player loses by touching a scratching post, or the top or bottom edges of the screen.

## Helper Functions

The game code has 5 helper functions which carry out some of the game play functionality. Each is listed below with a brief description of it's purpose.

- `swap_trail()` - Swap the trail back and forth between rainbow and trans flag colors.
- `draw_trail()` - Draw the trail at the current location.
- `erase_trail()` - Erase the trail at the current location.
- `shift_trail()` - Shift the pixel locations in the trail to the left by one.
- `shift_post()` - Move the posts to the left by one step.

## Display Elements

The display elements are broken up into a few different `Group`s with different scale factors applied. Each is listed below with a brief description of what it holds.

- `main_group` - The top level displayio `Group` that holds everything else within the game. The `Post` objects are added directly to this group, and are the only display element that is rendered at 1:1 size instead of scaled up by a `Group`.
- `scaled_group` - This `Group` gets scaled 2x. It holds the background, the cat sprite, and the trail canvas group.
- `bg_group` - This is scaled by 10x and put inside of `scaled_group` for an additional 2x making the total scale factor `20`. That allows it to contain a very small Bitmap with the dark blue background, but scale it all the way up to match the display size.
- `canvas_group` - This group is scaled 2x, and is placed inside of the `scaled_group` which brings the total scaling factor to `4`. It holds the trail canvas Bitmap that the trail pixels are rendered into.
- `trail_bmp` - A Bitmap that is 1px wide and 6px tall. It holds one column of the trail. It's contents will get copied into the canvas `Bitmap` with `bitmaptools.blit()`.
- `nyan_tg` - This `TileGrid` holds the cat sprite that represents the player. It's y location is changed in accordance with the gravity calculation, and jump button. It's `x` location remains static.
- `score_lbl` - A text label that goes in the bottom left corner and shows the current score.
- `game_over_lbl` - A text label that gets splashed on top of the game when the player loses.


## Featured Products

### Adafruit Metro RP2350

[Adafruit Metro RP2350](https://www.adafruit.com/product/6003)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town". This train is piled high with hardware that complements the Raspberry Pi RP2350 chip to make it an excellent...

In Stock
[Buy Now](https://www.adafruit.com/product/6003)
[Related Guides to the Product](https://learn.adafruit.com/products/6003/guides)
### Adafruit Metro RP2350 with PSRAM

[Adafruit Metro RP2350 with PSRAM](https://www.adafruit.com/product/6267)
Choo! Choo! This is the RP2350 Metro Line, making all station stops at "Dual Cortex M33 mountain", "528K RAM round-about" and "16 Megabytes of Flash town" and a bonus stop at "8 Megabytes of PSRAM village". This train is piled high with hardware that...

In Stock
[Buy Now](https://www.adafruit.com/product/6267)
[Related Guides to the Product](https://learn.adafruit.com/products/6267/guides)
### Adafruit RP2350 22-pin FPC HSTX to DVI Adapter for HDMI Displays

[Adafruit RP2350 22-pin FPC HSTX to DVI Adapter for HDMI Displays](https://www.adafruit.com/product/6055)
You may have noticed that our [RP2350 Feather](https://www.adafruit.com/product/6000) has an FPC output connector on the end&nbsp;for accessing the HSTX (High Speed Transmission)&nbsp;peripheral. This new capability, not available on the RP2040, is specifically designed to allow the...

In Stock
[Buy Now](https://www.adafruit.com/product/6055)
[Related Guides to the Product](https://learn.adafruit.com/products/6055/guides)
### USB Type A Jack Breakout Cable with Premium Female Jumpers

[USB Type A Jack Breakout Cable with Premium Female Jumpers](https://www.adafruit.com/product/4449)
If you'd like to connect a USB-host-capable chip to your USB peripheral, this cable will make the task very simple.&nbsp; **There is no converter chip in this cable!** &nbsp;It's basically a plain USB cable that's cut in half and with jumper sockets on the power and data...

In Stock
[Buy Now](https://www.adafruit.com/product/4449)
[Related Guides to the Product](https://learn.adafruit.com/products/4449/guides)
### Break-away 0.1" 36-pin strip male header - Black - 10 pack

[Break-away 0.1" 36-pin strip male header - Black - 10 pack](https://www.adafruit.com/product/392)
Breakaway header is like the duct tape of electronics. It's great for connecting things together, soldering to perf-boards, fits into any breakout or breadboard, etc. We go through these guys real fast, and thought that given how handy they are, we'd offer them in a pack of ten!<br...></br...>

In Stock
[Buy Now](https://www.adafruit.com/product/392)
[Related Guides to the Product](https://learn.adafruit.com/products/392/guides)
### 22-pin 0.5mm pitch FPC Flex Cable for DSI CSI or HSTX - 20cm

[22-pin 0.5mm pitch FPC Flex Cable for DSI CSI or HSTX - 20cm](https://www.adafruit.com/product/6036)
Connect this to that when a 22-pin FPC connector is needed. This 20 cm long cable is made of a flexible PCB. It's A-B style, meaning that pin one on one side will match with pin one on the other. How handy!

[We're stocking this to...](https://www.adafruit.com/category/360)

In Stock
[Buy Now](https://www.adafruit.com/product/6036)
[Related Guides to the Product](https://learn.adafruit.com/products/6036/guides)
### USB Type A to Type C Cable - approx 1 meter / 3 ft long

[USB Type A to Type C Cable - approx 1 meter / 3 ft long](https://www.adafruit.com/product/4474)
As technology changes and adapts, so does Adafruit. This&nbsp;&nbsp; **USB Type A to Type C** cable will help you with the transition to USB C, even if you're still totin' around a USB Type A hub, computer or laptop.

USB C is the latest industry-standard connector for...

In Stock
[Buy Now](https://www.adafruit.com/product/4474)
[Related Guides to the Product](https://learn.adafruit.com/products/4474/guides)
### Adafruit Fruit Jam - Mini RP2350 Computer

[Adafruit Fruit Jam - Mini RP2350 Computer](https://www.adafruit.com/product/6200)
We were catching up on a recent [hackaday hackchat with eben upton](https://hackaday.io/event/202122-raspberry-pi-hack-chat-with-eben-upton)&nbsp;and learned some fun facts: such as the DVI hack for the RP2040 was inspired by <a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/6200)
[Related Guides to the Product](https://learn.adafruit.com/products/6200/guides)

## Related Guides

- [Adafruit RP2350 22-pin FPC HSTX to DVI Adapter](https://learn.adafruit.com/adafruit-rp2350-22-pin-fpc-hstx-to-dvi-adapter.md)
- [Adafruit Metro RP2350](https://learn.adafruit.com/adafruit-metro-rp2350.md)
- [Adafruit Fruit Jam](https://learn.adafruit.com/adafruit-fruit-jam.md)
- [Chip's Challenge on Fruit Jam and Metro RP2350](https://learn.adafruit.com/256-color-gaming-on-the-metro-rp2350.md)
- [Snake Game on Metro RP2350](https://learn.adafruit.com/snake-game-on-metro-rp2350.md)
- [Larsio Paint Music](https://learn.adafruit.com/larsio-paint-music.md)
- [How to Choose a Microcontroller](https://learn.adafruit.com/how-to-choose-a-microcontroller.md)
- [Driving TM1814 addressable LEDs](https://learn.adafruit.com/driving-tm1814-addressable-leds.md)
- [Minesweeper on the Fruit Jam and Metro RP2350](https://learn.adafruit.com/minesweeper-on-metro-rp2350.md)
- [Return to The Matrix with the Metro RP2350 or Fruit Jam](https://learn.adafruit.com/return-to-the-matrix-with-the-metro-rp2350.md)
- [Create a Memory Game on Fruit Jam Metro RP2350](https://learn.adafruit.com/create-a-memory-game-on-metro-rp2350.md)
- [Using DVI Video in CircuitPython](https://learn.adafruit.com/using-dvi-video-in-circuitpython.md)
- [Solderless Robot Toy Xylophone](https://learn.adafruit.com/solderless-robot-toy-xylophone.md)
- [Breakout Game on the Metro RP2350 and Fruit Jam](https://learn.adafruit.com/breakout-game-on-metro-rp2350-and-fruit-jam.md)
- [Match3 Game on the Fruit Jam and  Adafruit Metro RP2350](https://learn.adafruit.com/match3-game-on-metro-rp2350.md)
- [Using a Mouse with USB Host](https://learn.adafruit.com/using-a-mouse-with-usb-host.md)
- [Touch Tone Phone Dial-a-Song](https://learn.adafruit.com/touch-tone-phone-dial-a-song.md)
- [Adafruit Proto Tripler PiCowbell](https://learn.adafruit.com/adafruit-proto-tripler-picowbell.md)
