# Bounce - an accelerometer game in Arduino for PyGamer and PyBadge

## Overview

https://youtu.be/M7nBsI7jkZc

Back in ye olde 2013, Arduino came out with the Arduino Esplora. It was much like an Adafruit Circuit Playground Express and an Adafruit PyGamer rolled into one board. With an add on display, you had about a $100 self-contained handheld device (without a provision for a battery). Few games were made for the Esplora at the time. The author ported two games, Bounce and Pong, and even added an Adafruit MintyBoost to get it portable on a LiPo battery. The cost and the features did not find a market and the Esplora was quietly discontinued.

Fast forward to today: boards with modern microcontrollers and displays are proliferating, thanks to the lowering of costs and environments like MakeCode Arcade, allowing anyone to make graphical games! Several companies are making boards in this format including a number from Adafruit's PyGamer and PyBadge.

I told Ladyada I'd port one of the Arduino games from Esplora to PyGamer and she said "Go for it!". It was not difficult: if your old program used the Adafruit GFX Arduino library (and most Arduino display-based code uses that open source code), you can easily port the game to the modern Adafruit Arcada game libraries which are a superset of Adafruit GFX.

This game was originally written by R0d0t and featured in Hackaday back in 2012. It's been ported to Arcada and the scoring and controls have been improved.

Precompiled versions are available in UF2 format to drop onto your compatible boards.

## Parts

The original Adafruit PyBadge or PyGamer boards work - an accelerometer is needed so the PyBadge LC is not compatible.&nbsp;

Featured
### Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino

[Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino](https://www.adafruit.com/product/4242)
What&nbsp;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 PyGamer!** We wanted to make an entry-level gaming handheld for DIY gaming, and maybe a little...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4242)
[Related Guides to the Product](https://learn.adafruit.com/products/4242/guides)
![Angled shot of Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino.](https://cdn-shop.adafruit.com/640x480/4242-00.jpg)

Featured
### Adafruit PyGamer Starter Kit

[Adafruit PyGamer Starter Kit](https://www.adafruit.com/product/4277)
**Please note: you may get a royal blue _or_ purple case with your starter kit (they're both lovely colors)**

What&nbsp;fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4277)
[Related Guides to the Product](https://learn.adafruit.com/products/4277/guides)
![Adafruit PyGamer Starter Kit with PCB, enclosure, buttons, and storage bag](https://cdn-shop.adafruit.com/640x480/4277-08.jpg)

Featured
### Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino

[Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino](https://www.adafruit.com/product/4200)
What's the size of a credit card and can run CircuitPython, MakeCode Arcade or Arduino? That's right, its the **Adafruit PyBadge!** We wanted to see how much we could cram into a ​3 3⁄8 × ​2 1⁄8 inch rounded rectangle, to make an all-in-one dev board with...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4200)
[Related Guides to the Product](https://learn.adafruit.com/products/4200/guides)
![Angled shot of a Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino. ](https://cdn-shop.adafruit.com/640x480/4200-01.jpg)

Featured
### Mini Oval Speaker with Short Wires - 8 Ohm 1 Watt

[Mini Oval Speaker with Short Wires - 8 Ohm 1 Watt](https://www.adafruit.com/product/4227)
Hear the good news! This wee speaker&nbsp;is&nbsp;a&nbsp;great addition to any audio project where you need 8 ohm impedance and 1W or less of power. We particularly like this&nbsp;speaker&nbsp;as it is&nbsp;small and comes with nice skinny wires with a connector on the end. It has a handy...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4227)
[Related Guides to the Product](https://learn.adafruit.com/products/4227/guides)
![Mini Oval Speaker with Short Wires ](https://cdn-shop.adafruit.com/640x480/4227-06.jpg)

# Bounce - an accelerometer game in Arduino for PyGamer and PyBadge

## Programming

## Want to play now?

Download one of the following UF2 files for your particular device:

[PyBadge_Bounce.UF2](https://cdn-learn.adafruit.com/assets/assets/000/077/524/original/PyBadge_Bounce.UF2?1561571094)
[PyGamer_Bounce.UF2](https://cdn-learn.adafruit.com/assets/assets/000/077/526/original/PyGamer_Bounce.UF2?1561571115)
Double click the reset button to get to the UF2 screen. Go to the appropriate flash drive that appears on your computer - **PYBADGEBOOT** or **PYGAMERBOOT** and copy over the correct UF2 file from above and the device should reboot and start the game.

## Compiling the Game in Arduino
The code uses the Adafruit Arcada library. Arcada is a full featured set of game creation and display functions. It can be thought of the older Adafruit GFX library on super steroids.

In the Arduino IDE, you will need to use the Library manager to load a BUNCH of helper libraries. Please take the time to get the latest versions to ensure you have the latest code tweaks.

[Guide to loading all the helper libraries required for Arcada](https://learn.adafruit.com/adafruit-pybadge/arcada-libraries)
The code also requires a recent Adafruit SAMD boards file. Version 1.5 or higher. Go to the boards manager via the steps listed below.

![](https://cdn-learn.adafruit.com/assets/assets/000/077/522/medium800/gaming_boardmgr.png?1561563966)

Type "samd" into the search. The first couple of entries will probably not be the Adafruit package. You want to install the package called **Adafruit SAMD Boards** by **Adafruit** and _be sure the version is 1.5 or higher_.

This will give you the support for the Adafruit PyGamer and PyBadge definitions for the game.

![gaming_samd.png](https://cdn-learn.adafruit.com/assets/assets/000/077/523/medium640/gaming_samd.png?1561564170)

Once you have the latest board definitions, you can select the **Adafruit PyGamer** or the **Adafruit PyBadge** for the game depending on your board. The PyBadge LC will not work as it does not have an accelerometer to provide the game interactivity.

## Code

If you click the **Download: Zip** link, you should get both the **bounce.ino** and **logo.h** files. Save them in your Arduino projects directory in a subdirectory named **bounce**.

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/PyGamer_Bounce_Game/bounce/bounce.ino

https://github.com/adafruit/Adafruit_Learning_System_Guides/blob/main/PyGamer_Bounce_Game/bounce/logo.h

# Bounce - an accelerometer game in Arduino for PyGamer and PyBadge

## Gameplay

The game is played in portrait mode so you'll turn your PyGamer or PyBadge 90 degrees.

There is an introductory screen - press **START** to continue.

### Basics

The display consists of a bouncing ball which bounces when it hits a flat surface (it can pass through the bottom of platforms but bounces on the tops of the platforms).

The goal is to have as many platform bounces as you can without the ball hitting the floor.

You tilt the board left and right so move the ball side to side to get on the platform you want to bounce off of. Currently tilting up and down does not activate anything.

The ball will move off the screen to the right or left to the other side - handy if the platform you want to bounce off of is too far away for a cross-screen bounce.

When the ball is yellow, it is in play and the count of bounces is on the lower right on the screen. After one play, there is a last game score below the ground level and a high score count at the bottom of the display.

You can pause the game by pressing the **START** &nbsp;button. The screen will freeze. Pressing any other button will start the game back up.

### Sound

The default is sound on. You can use the **SELECT** button to toggle sound off and on. A red ø symbol is displayed in the lower right of the screen if the sound is muted. The buttons are not debounced - if you press **SELECT** and it still is muted, keep pressing until it is unmuted.

### Bonuses

There are 4 types of bonuses that are triggered when hitting a colored platform. Use the A button to activate the bonus. The type of bonus is listed at the bottom of the display and only lasts a short time.

## Going Further

There is a number of ways to extend the game in code. If top to bottom movements are detected, it could increase or decrease gravity some. If moving offscreen to the other side isn't your cup of tea, you can detect when the ball hits the bounds and bounce back at the same speed. There are still lots of buttons and NeoPixels not in use for input and output.


## Guide Products

### Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino

[Adafruit PyGamer for MakeCode Arcade, CircuitPython or Arduino](https://www.adafruit.com/product/4242)
What&nbsp;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 PyGamer!** We wanted to make an entry-level gaming handheld for DIY gaming, and maybe a little...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4242)
[Related Guides to the Product](https://learn.adafruit.com/products/4242/guides)
### Adafruit PyGamer Starter Kit

[Adafruit PyGamer Starter Kit](https://www.adafruit.com/product/4277)
**Please note: you may get a royal blue _or_ purple case with your starter kit (they're both lovely colors)**

What&nbsp;fits in your pocket, is fully Open Source, and can run CircuitPython, MakeCode Arcade or Arduino games you write yourself? That's right,...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4277)
[Related Guides to the Product](https://learn.adafruit.com/products/4277/guides)
### Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino

[Adafruit PyBadge for MakeCode Arcade, CircuitPython, or Arduino](https://www.adafruit.com/product/4200)
What's the size of a credit card and can run CircuitPython, MakeCode Arcade or Arduino? That's right, its the **Adafruit PyBadge!** We wanted to see how much we could cram into a ​3 3⁄8 × ​2 1⁄8 inch rounded rectangle, to make an all-in-one dev board with...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4200)
[Related Guides to the Product](https://learn.adafruit.com/products/4200/guides)
### Mini Oval Speaker with Short Wires - 8 Ohm 1 Watt

[Mini Oval Speaker with Short Wires - 8 Ohm 1 Watt](https://www.adafruit.com/product/4227)
Hear the good news! This wee speaker&nbsp;is&nbsp;a&nbsp;great addition to any audio project where you need 8 ohm impedance and 1W or less of power. We particularly like this&nbsp;speaker&nbsp;as it is&nbsp;small and comes with nice skinny wires with a connector on the end. It has a handy...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4227)
[Related Guides to the Product](https://learn.adafruit.com/products/4227/guides)
### Pink and Purple Braided USB A to Micro B Cable - 2 meter long

[Pink and Purple Braided USB A to Micro B Cable - 2 meter long](https://www.adafruit.com/product/4148)
This cable is&nbsp;super-fashionable&nbsp;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, and if you&nbsp;_have_&nbsp;to have visible cables, then you might as well have the nicest fabric-bound...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/4148)
[Related Guides to the Product](https://learn.adafruit.com/products/4148/guides)

## Related Guides

- [Adafruit PyBadge and PyBadge LC](https://learn.adafruit.com/adafruit-pybadge.md)
- [Introducing Adafruit PyGamer](https://learn.adafruit.com/adafruit-pygamer.md)
- [Your First Power Switch Relay Project - Circuit Playground Smart Plug](https://learn.adafruit.com/beginner-first-project-power-switch-relay-circuit-playground-smart-plug.md)
- [Motion Sensor Bat](https://learn.adafruit.com/motion-sensor-bat.md)
- [Blinka Jump PyBadge Game](https://learn.adafruit.com/blinka-jump-pybadge-game.md)
- [ Faz-Wrench - Five Nights at Freddy's](https://learn.adafruit.com/faz-wrench.md)
- [Make a Zelda Master Sword with the RP2040 Prop-Maker Feather](https://learn.adafruit.com/master-sword-rp2040.md)
- [PyPortal IoT Plant Monitor with Google Cloud IoT Core and CircuitPython](https://learn.adafruit.com/pyportal-iot-plant-monitor-with-google-cloud-iot-core-and-circuitpython.md)
- [Trash Panda: The Game](https://learn.adafruit.com/trash-panda-the-game.md)
- [CircuitPython Turtle Graphics](https://learn.adafruit.com/circuitpython-turtle-graphics.md)
- [Mouse Painter: Emulate Mice with MakeCode ](https://learn.adafruit.com/mouse-painter-emulate-mice-with-makecode.md)
- [PyPortal Tides Viewer](https://learn.adafruit.com/pyportal-tides-viewer.md)
- [Re-MakeCode the Classics: Py Hunter](https://learn.adafruit.com/re-makecode-the-classics-spy-hunter.md)
- [PyPortal WFH Busy Sounds Simulator](https://learn.adafruit.com/pyportal-wfh-busy-sounds-simulator.md)
- [Burning Fire Wizard Staff](https://learn.adafruit.com/burning-fire-wizard-staff.md)
- [Easter Egg Light Stand](https://learn.adafruit.com/easter-egg-light-stand.md)
- [Make It Glow: How to Solder NeoPixels, A Beginner's Guide](https://learn.adafruit.com/make-it-glow-how-to-solder-neopixels-a-beginners-guide.md)
