Why we built it

Liverpool MakeFest is a family-friendly event celebrating low level technologies, hardware, hacking and making. We participated with a stand at the 2018 event and built the Dungeon Crawler game to engage with those attending and learn more about Redux, Firebase and Android Things for ourselves.

We based our game on the original Line Wobbler and on Twang which is an open-source version of the game, built for Arduino.

Dungeon Crawler uses an LED strip as a display, where the player, enemies, and other game entities are represented as different LED colours. The player can be controlled with a joystick that’s built using a spring from a doorstop, which includes a gyro & accelerometer sensors to determine the movement speed or if the user is attacking.

Paul playing a sneaky game before MakeFest ended

We ported all the game logic to Java/Kotlin running on Android Things and once it was working with the hardware, we decided to take it one step further to explore how we could make the experience even more engaging. We considered multiple options, but one that really caught our attention was having a replay feature. After someone plays a game, the game stores the replay as JSON in Firebase in order to replay it later on. Using the Redux architecture enables this feature as we store a list of game states (one for each frame) as the game progresses, and at the end of the game, we store the list of states in a Firebase Database. Additionally, we built a companion app, which can run on a regular Android device. The companion app observes for new game replays in Firebase and when there’s a new one, it pulls it and replays it on the separate tablets screen.

The companion app replaying a game

See the full blog post here.

How we built it

First of all we converted the code from the TWANG game to Java and then we modified the game loop so that we could tie it to Android's Activity Lifecycle, as we wanted to make sure we could get the game logic working and compiling before proceeding to the hardware side of things.

The first version of the game running on an Android emulator

Once we had the game working on an Android device, it was time to tackle the hardware side of this project. We started with the joystick. We built the first version of the joystick by screwing the door stop to a piece of wood and the MPU6050 sensor to the head of the door stop. Then wired it to a breadboard and to the Raspberry Pi. Next, we decided to convert the Arduino code to communicate with the sensor to Android Things. After some struggling with the configuration and with maths, we realised that we were writing to the SPI bus incorrectly, and managed to fix it when we found about this MPU6050 driver for Android Things (we ended up leaving our implementation with the fixes from that repo). Finally, we were able to read data from the sensor and wobble it as a player would do when playing the game!

First version of the joystick

Next up was the display. In order to power the whole LED strip (5 meters long, so 300 LEDs), we had to use a separate power supply to make sure the LEDs would be bright enough. The product details mention that the LED strip uses 18W/meter, so since we wanted to use the whole LED strip, it would be using 90W in total. The working voltage of the LEDs is 5V, so the maths are as follows:

I = P / V = (18W * 5m) / 5V = 90W / 5V = 18A

So we had to use a power supply that could output 18A at 5V. We decided to get this one, and it worked great! We decided that it'd make sense to use the same power supply for the Raspberry Pi as well, since it also works at 5V, so we cut the end of a USB cable and used it to connect the Pi to the PSU.

We'd only need 1 wire out to the power socket!

Getting the Apa102 LED strip working with Android Things was rather simple, since we already had some experience with working with LED strips in Android Things and there's already a driver for the Apa102 that works out of the box. No major issues here, we just had to convert the Twang code that was using Arduino's FastLED library to work with the Apa102 Android Things driver, and everything worked.

Using the Apa102 LED strip for the first time

At this point we had the joystick and the display working! It was a matter of putting it all together. Xavi's dad designed a 3D model of a case for this project and 3D-printed it. It came out pretty nicely!

The PSU and the Pi are screwed to the case

We also 3D-printed the head (we took the same design that is provided in the Twang project):

Different colours for style points!

Inside the head we put the MP6050 sensor, and we used some glue to make sure the head would stay in place attached to the door stop. The wires to the sensor would go through the spring of the door stop and connected to the Pi directly.

In the end we only used 4 wires instead of all 8

At the top of the case, we mounted the door stop and the joystick was complete:

We used an Ethernet cable as they are quite rigid

Now, we just had to close the case and connect the LED strip (which comes out of the small hole at the end of the case:

Just before closing it. We used an NXP board for this one, instead of the Pi, but both boards work

And voilà:

The finalised product

Next, we decided to implement the code to store replays (using Firebase). The idea was that we would store in memory the current game state for every frame of the game and then, when the game is over (or if the player completes the game), it would store in Firebase the whole list of game frames.

The database contains the list game replays, with the game frames and the gamer tag

Next to the game, we had a display that was showing an Android Emulator running the Companion app. This companion app would get notified whenever a new replay was pushed to Firebase and it'd pull it and replay it:

The companion app replaying someone's game

We also added an EditText to let people type their gamer tag so that the replay would be stored with their name!

That's it, the game was ready for showcase:

Our booth at Liverpool MakeFest 2018

We hope this inspires other people to create interactive games and experiences that can help engage kids in technology. If you have further questions contact us (@bludell_apps & @xrigau) on Twitter! Happy hacking!