Welcome to the first in a series of posts on the Arduboy game released by Modus Create over the holidays. This was originally intended as a single post, but we soon discovered that there was so much to say we’ve had to break it out into a series. We’re going to try and maintain a table of contents here in this post and update the links out to the subsequent posts as we publish them. So, without further ado…
Table of Contents
- Announcing EVADE, our first Arduboy Game
- Creating EVADE, a Side Scrolling Shooter Game for Arduboy
- Introduction and Setup (this post !)
- Text
- User Input
- Memory Management and EEPROM
- Images
- Collision Detection
- Music
- Sound Effects
- Designing EVADE
Building Something Novel
For this year’s holiday season, we wanted to give a lasting and novel gift to clients and team members. Rather than sending a box of chocolates, gift card or similar we decided that we should make something unique ourselves that spoke to what we do best.
After canvassing ideas from the team and assessing their feasibility, we settled on writing a game for the Arduboy, a credit card sized games console reminiscent of the original Nintendo Gameboy.
What is the Arduboy?
The Arduboy is based on the popular Arduino hardware and is open source. It has six buttons, four of which are laid out for directional control with the others positioned as fire / action buttons. The device has a black and white OLED display, a programmable LED and a two channel speaker. The Arduboy demo video provides a great walkthrough of the device’s capabilities.
We chose Arduboy because we were excited about putting something interactive into our customers’ hands, and it had a personal appeal to many members of the team for whom retrogaming remains a popular hobby. Choosing Arduboy also allowed us to focus on defining, delivering and managing a software project using a distributed team which is a core competency that our customers recognize us for.
What to Build?
Having settled on Arduboy as our off the shelf hardware, we then had to figure out what sort of game to build. We thought about puzzle games, platformers and shooters. As many of us cut our gaming teeth on space shooters, we decided we’d like to build one of those, and opted for a side scrolling game in the spirit of the classic R-Type.
Alien Invasions and Weapons
After further brainstorming, we decided to set out and build a game where the player is escaping from an alien invasion, and would face waves of enemies including three different “bosses” – larger, faster, and tougher than the regular foes. As the Arduboy has two “fire” buttons, we decided we should arm our hero’s ship with one weaker strength weapon that they can use at will, plus a much more powerful weapon that depletes an energy reserve with each shot so that the player has limited use of it before they have to wait for it to “recharge”.
We also decided that the player should face multiple enemies at a time, with different types of enemies requiring different numbers of hits to kill them. Each enemy would have a health score, and each of the player’s two weapons would deplete this by differing amounts when an enemy was hit — the limited use weapon causing more damage. The player’s ship should be fragile, and be destroyed by a single hit from any enemy: to combat this fragility we decided to give the player four lives and to make their ship and weaponry a little faster moving than that of the enemies.
Bosses and Levels
As is customary, we also wanted to add “bosses” – larger, tougher enemies that the player has to face at strategic points as the game unfolds. We also wanted this to be an “infinite” game, so after the user has beaten all the enemies and bosses once, they get to do it all over again (with the enemies becoming stronger and harder to beat each time until the player dies).
We chose to represent progress by keeping score rather than having “levels”. The player earns points for staying alive, with extra points for each regular enemy that they shoot down and bonus points for beating a boss. In keeping with the retrogaming / arcade spirit, we chose to implement a classic “3 initials” high score table, and give the the game fast paced music that changes when the player faces off against a boss.
Before diving into how we went about building Evade, check out the trailer video that we produced for it…
EVADE Cinematic trailer from Modus Create on Vimeo.
Game Programming on the Arduboy
The Arduboy uses the Arduino electronics platform, so developing for Arduboy is largely similar to developing for Arduino but focussed on gaming applications due to the nature of the inputs available (six buttons). The open source Arduino IDE provides a basic code editing environment for the C language, compiling it, and uploading it to the device which connects to the developer’s machine via a USB cable.
Arduino programs are known as “sketches”, and a game for the Arduboy is just another type of sketch, so anyone familiar with Arduino programming will be able to dive right in with the Arduboy.
Arduino Libraries
The Arduino community provides many useful code libraries for working with the hardware, and the Arduboy is no exception to this. There are a couple of libraries that wrap the low level calls to manage the hardware for things like detecting a button press, drawing shapes / pixels on the screen rendering a bitmap image and playing sounds. We decided to use the official Arduboy Library which is open source and available both within the Arduino IDE and from GitHub. There’s a good guide to getting started with Arduboy using the Arduboy library over at arduboy.com.
Working with the Arduino IDE
Although the Arduino IDE is relatively basic, it does provide the essentials. If you find that you miss some of the bells and whistles of your favorite IDE, you can enable the “Use external editor” option under Preferences > Settings. Enabling this will cause the Arduino IDE to reload the sketch when it detects file changes (ie when you save from your external editor) and will prevent you from making edits in the Arduino IDE itself.
Initialization and the Game Loop
Sketches have, at minimum, two very important functions:
setup()
– which contains all of your game initialization. This is where you’ll want to set any initial values, perhaps show your intro screen and callarduboy.begin()
.loop()
– this is the main game loop for your sketch and is focused on handling input, updating and rendering.
As your sketch grows, you may want to refactor it into multiple files and then include them into your main arduboy-game.ino
file. For example:
#include "enemy.h"
Compiling and Uploading
Simply click the check mark on the toolbar or select Sketch >> Verify/Compile and the Arduino IDE will compile your sketch and display all of the warnings and errors in the bottom of the window.
Uploading the sketch to the Arduboy is also easy. Click the right arrow on the toolbar or select Sketch >> Upload to compile and upload your game. Note that rather large sketches can be a bit finicky to upload. (See the Gotchas section below)
Debugging
Debugging on the Arduboy is quite limited. Generally, the approach is to print text straight to the screen or print to the Serial Monitor by:
- Setting the baud rate with
Serial.begin(9600)
- Logging messages and values with
Serial.println()
orprint()
- Click the magnifying glass or select Tools>>Serial Monitor to view your output.
Gotchas
Whilst developing Evade, we came across a few things that can trip up those new to working with the Arduino IDE and Arduboy:
- The Arduino IDE doesn’t reload files from disk if they change whilst it has them open. This can cause some issues when working in a team, as it is common to change branch in git at the command line. This may change the files, so that the version you are looking at in the IDE is now out of sync with what’s on the disk. We generally got around this by closing and re-opening the IDE when changing branches, but we could also probably have used the “External Editor” option in the IDE and edited the code in another editor such as Sublime Text or VS Code.
- There is really limited debugging capability; the IDE isn’t able to inspect a running program on the Arduboy which limited us to using
Serial.print
or temporary text on the screen. - As our sketch started to become larger and approach the maximum limit of the device’s RAM, we found we couldn’t upload new code to the device without resetting it using the recessed reset button in the bottom. A paperclip or toothpick became part of the process 🙂 Turns out that this seems to be a known issue when uploading code that approaches the memory limits.
Game Over
Creating Evade was incredibly fun not only because of the game content but because writing in C on the Arduboy forced us to think differently… and that’s a good thing. Most of the team had to quickly learn both C coding and the Arduino environment. The cognitive load for everyone was high, but we need to go beyond our comfort zones if we are to grow as developers. This project was the perfect opportunity to do that.
We also found that we could still manage the team like it was any other software project. We set up a Trello board and held standups. We used Github for version control and Slack/Hangouts for communication. In fact, we have a series of blog posts coming for Evade where we plan to share everything from how the project was managed to how the music was made.
Play Evade !
If you’d like to play our game yourself, you’ll need:
- An Arduboy device ($49) from arduboy.com, Adafruit, or Pimoroni (United Kingdom)
- The Arduino IDE (free), works on Mac, Windows and Linux, required to install our code
- Our code, which is open source and downloadable from GitHub where you will also find instructions on compiling and installing it using the Arduino IDE
Let Us Know What You Think
We hope you enjoy playing our game as much as we enjoyed writing it. Next up, stay tuned for our first in-depth post on the programming of EVADE: Getting Things Done with Text.
In the meantime, we’d love to see pictures of your high scores. So, tag us on Instagram or tweet us a photo of your high scores using the hashtag #evadehighscore.
New #evadehighscore @ModusCreate #arduboy: 55,486 pic.twitter.com/lckrBzuxpG
— freshyseth (@freshyseth) December 25, 2016
Timothy Eagan
Related Posts
-
EVADE featured in Arduboy Magazine
On Friday February 24, 2017, we were excited to learn that our game, EVADE, was…
-
Announcing EVADE, our first Arduboy Game
EVADE is Modus's very first game for the Arduboy platform. Learn how a highly performing…