Amani profile photo

Amani

Thoughts, realizations, accomplishments

Amani Kilumanga

3 minutes read

These days, I’ve been trying my hand at some of the games in my constantly growing collection on Steam. One of those games, is BIT.TRIP RUNNER.

BIT.TRIP RUNNER, is a rhythmical, side-scrolling game, where the goal is to navigate a character, who you cannot stop from running, over pits and around obstacles. The game hosts some excellent pixel-art and a very pleasant soundtrack (one that adapts to your gameplay), and the controls are simple enough that anyone can get started with it. It’s no wonder that it is such a massive hit.

So I made it through the opening levels where you are taught all the game’s mechanics. However, a few levels in, I could tell that this wasn’t going to be my kind of game. I mean, I love the idea of having to master rhythms and being able to glide around in a beautiful pixelated landscape, but the game is just too punishing. Every tiny little misstep sends you back to the beginning of the stage. And there is so much opportunity to make those missteps.

So I came up with the idea to just program a bot to play the game for me. The result is a Java program currently about a few tens of lines available on GitHub. See: dkaksl/bit-trippy.

Before I go into technical details check out a demonstration of the bot (in its current state) playing Lv 1-1. You can tell that it is a current video due to the Christmas themed cape at about 50 seconds in. I didn’t capture my keyboard, however, so you’re going to have to believe me when I say that the bot was the only one playing.

So how does it work? Well, the program uses the Robot class to simulate keyboard input. Simulating keypresses only requires the following:

  1. A keyPress event
  2. An optional delay
  3. A keyRelease event

You can see a very straightforward implementation of the above in my pressKey method:

private void pressKey(Robot robot, int event, int delay) {
	robot.keyPress(event);
	robot.delay(delay);
	robot.keyRelease(event);
}

Combinations of keypresses can be simulated by ordering the press and release events so that multiple keys are in the pressed state simultaneously. You can see an example of this in my altTab method:

private static void altTab(Robot robot) {
	robot.keyPress(KeyEvent.VK_ALT);
	robot.keyPress(KeyEvent.VK_TAB);
	robot.keyRelease(KeyEvent.VK_ALT);
	robot.keyRelease(KeyEvent.VK_TAB);
}

So the bot is simply programmed to wait x number of milliseconds before pressing a key (in the above example, the space key). Theoretically, the program can be set up to handle everything from execution of the game to playing it, but in its current state, it only works by setting the game up to be paused on the first level, with the cursor pointed at the “Restart” menu item. The program executes an Alt + TAB and starts pressing the space key with predefined delays. I might come back to this project and add more features in the future, automating more of the game.

Oh and do beware that the program only has been tested on my machine, so there is a chance that it won’t run as smoothly on another system. One thing I noticed was that the bot and game came out-of-sync when I was running screen capturing software on 120fps. So any little bit of lag will throw the timings off.

So there you have it. A demonstration of an open source BIT.TRIP RUNNER bot, with instructions on how to make one of your own. DISCLAIMER: If you do decide to run, or mimic my code, beware that it might be considered cheating and in violation of some agreement you may or may not have signed.

Categories

About

A creative and meticulous Software Engineer who is passionate about delivering robust and general solutions through an iterative development process.