Native Linux Games for an Arcade Cabinet: Playing "Titan Attacks!" Without a Mouse

| Comments

Puppy Games bills “Titan Attacks” as “The best Space Invaders tribute ever.” I definitely have to agree with them! There are plenty of different kinds of alien ships and they all seem to move around the screen differently. Some act just like old-school space invaders, some wrap around the screen, some of the meaner ones drop bombs and swoop down at you. I never seem to keep my multiplier built up for the boss battles, though…

The sound-track is a perfect fit for this game and the awesome retro style graphics make this game a fitting addition to my arcade cabinet.

The game is played with the keyboard, so it was no problem to map my arcade controls to match the keys. The problem is that “Titan Attacks” requires a mouse for some very important functions. You need a mouse to start a new game, to purchase upgrades in between stages, and to exit the game. My arcade cabinet does not have a mouse or a trackball…

I figured it would be pretty trivial to bind some automated mouse clicks to various button combinations. The mouse scripting was very easy thanks to xmacro. Binding the keys wasn’t as easy as I hoped.

xbindkeys Failure

When a game grabs the X11 keyboard, it sure doesn’t tend to let anything escape. Most games I tried intercepted all the keystrokes and didn’t let anything sneak past to xbindkeys. I had to intercept the keyboard at a lower level.

Reading /dev/input/event* Directly

I wrote up a quick and dirty Perl script to watch the event device associated with my keyboard (/dev/input/event2 on my cabinet) and watch for certain key combinations. When certain combinations are pressed, it calls the appropriate xmacro script.

If I’m going to do this for more games, I will have to sit down and design a better keyboard monitoring script. Continuing to write up piles of spaghetti-like if statements is definitely not something I want to do.

Trying to Assign Buttons in a Sensible Fashion

It turned out that I needed to bind nine scripts to different buttons. The first script is pretty overloaded. It attempts to do three different actions, all of which are related to starting a game. Six button bindings are needed for purchasing upgrades. One binding is to answer “no” when asked if you want to continue a saved game, and another is needed to exit the game.

I’m using the “start” button as a sort of shift key. My controllers all have six buttons, so I mapped “start” plus “button 1” to buy the first upgrade, “start” plus “button 2” to buy the second, and so on.

Holding “start” and pushing the joystick up attempts to do one of three things. First, it enters a name for the high score board; this is necessary at the end of a game. Then it attempts to click “yes” for when the game asks if you’d like to continue your saved game. Finally it clicks in the area where either the “begin game” or “continue” button are located.

This pretty much means that you click “start + up” any time you want to advance in the game, since it tries to click “yes” before it tries to start a new game. You also have the option of hitting the “no” button as well, which is “start + down”.

The “exit” button is over on one of the other control panels. I always try to keep the destructive buttons in harder-to-reach places.

How Well Does it Work?

Both better and worse than I expected. I had to add delays between the mouse button presses and releases to make things work more consistently. This sure makes the “yes/begin/continue” script execute like molasses. Even with the delay, the actions aren’t always picked up by the game. I would guess that they fail about 15% of the time, but sometimes the “continue” button fails two or three times in a row.

Starting the game also causes a few stray shots to be fired, mostly because of the delays between mouse clicks. I will probably have to rethink the idea of combining so many mouse clicks into a single macro.

Was it Worth the Effort?

It was definitely worth the effort. “Titan Attacks” is exactly the sort of game that belongs on an arcade cabinet. Puppy Games is having a sale on a bundle with “Titan Attacks,” “Ultratron,” and “Droid Assault” for only $7. They are all fun games; I sure wish my cocktail cabinet had a seat with dual joysticks so I could comfortably play the other two games on there.

Most of the hard work is out of the way now. It should be quite easy for me to add more games that require a mouse in the future.

I bundled up all the related files just in case anyone wants them. If and when I get around to creating a better solution, I will definitely make a copy available.