Dungeon of Tar — Custom Handheld Gaming Device
A custom-built and custom-programmed handheld gaming device.
Summary:
A game console based on the ATMega32u4. Every component and circuit board was 3D modeled, as well as the case, using SolidWorks. The wiring is hand-soldered using 30AWG wire. The structure is a 3D printed case using wood/PLA filament. The console uses a PSP(PlayStation Portable) 1000 joystick to control the player, a tact switch for dumping “tar” and filling in the areas around the player, as well as a beats per minute system so the level fills up with immovable blocks to the tune of each level’s song.
Components:
– 1x disassembled rechargeable battery pack from Amazon
– (^^ from the battery) 1x 5v/3v regulator
– 1x switch for power
– 1x ATMega32u4 (Arduino Micro)
– 1x Serial MP3 module
– 1x Auxiliary amplifier (5v) with volume controlled by potentiometer
– 1x PSP(PlayStation Portable) 1000 joystick
– 1x tact switch
– 1x (1W) speaker
Hardware limitations:
The code initializes the TFT screen over a hardware SPI connection that is also shared by the SD reader and selected using a chip select pin. The spotredraw() function was entirely written by me and controls a selective redrawing of the TFT screen since a full refresh is too slow. The many named update functions also selectively redraw spots on the screen such as the score, highscore, and “tar” items. Since the Arduino Micro cannot generate random numbers, the random number generator is fed raw input from the two joystick axes added to the current microsecond count every time the player moves.
The Game Logic:
What is displayed onscreen is mirrored as a character array of the same size and uses different symbols for each object. The ASCII table was replaced with a custom font, included in the header which I created using the “binFontsTool” Excel sheet in which a custom font can be drawn pixel by pixel. The joystick and tact switch are held in an infinite while loop to check for input, along with a seconds counter to drop in the “cracks.” The cracks and holes are the grey symbols that prevent the player from moving through. The orange icon clears all cracks (but not the holes) from the board and allows the player to once again pass through freely. Once in a while the player will get stuck in which the tact switch can be pressed up to three times per game to clear the surrounding array positions [logic found in cleancircle();] The player is also checked every loop to see if it has become trapped [checktrapped();] Once the player is out of “tar” and checktrapped() returns true, the game is stopped and the screen inverts the colors and writes the score if it’s higher to the EEPROM of the Arduino as a long datatype by EEPROMWriteLong(); since each address of the EEPROM is only one byte, in order to store the highscore even while the console is turned off.
Sprite-sheet Storage
This tool is made within Excel and allows for loading, editing, and saving custom pixel-based fonts specifically for the Adafruit GFX font library on the Arduino. This tool auto-compresses the data into a header file which can be referenced by the main code for drawing glyphs to the screen. I used the unused glyphs for the sprites of the game.
Ported to ATMega2560 and ILI9225 Screen
For my friend’s birthday I ported Dungeon of Tar onto a prototype board for my next project (SimmiMega) and changed the easter egg dialog to be a birthday card. Porting the graphics was easy—I overrode the function it used for calling the old TFT library and pointed it to the new one with some x offset and pixel scaling.
Music
The game gets quicker every 32 steps, starting with a 140bpm song and increasing up to a 260bpm song, all of which were written be me using a tool called “BeepBox.” The music is stored on a MicroSD card and played via a serial connection between the Arduino’s hardware serial pin and the RX pin of the SerialMP3 board.