famw / SpelunkBots

An API that allows for AI bots to be written in the original 2009 version of Spelunky.
http://spelunkbots.com
1 stars 0 forks source link

SpelunkBots

A C++ API that allows for bots to be written in the original 2009 version of Spelunky. For more information, check out the SpelunkBots homepage at http://t2thompson.com/projects/spelunkbots/

About this Fork

This fork allows us to run SpelunkBots on Linux.

Before Starting

After cloning the repo, you must get all submodules, you can do that running:

git submodule init ; git submodule update

Dependencies

Since SpelunkBots is built using GameMaker 8, we are not able to run it on Linux nativelly, therefore, wine is our hero.

Having wine installed we will need to cross compile SpelunkBots Code.

A good option to do the job is MXE, since it uses an updated version MinGW toolchain.

Cross Compiling Code

First of all, clone MXE repo:

git clone https://github.com/mxe/mxe.git

Make sure you have all MXE requirements.

Then, enter in MXE folder and install gcc cross compiler:

MXE_TARGETS='x86_64-w64-mingw32.static i686-w64-mingw32.static' make gcc

It will download some dependencies and install a gcc under <mxe-path>/usr/bin/ folder.

It's a little bit slow to install all the dependencies, so, grab a coffee and wait.

Compile DLL's

First of all, go to folder where you've installed MXE, then, export PATH to access MXE's binaries:

cd <mxe-folder>
export PATH=$PATH:$(pwd)/usr/bin

Now, we have access to all MXE binaries. Remember that it's a temporary setup, if you want to have it under your $PATH forever, add export PATH command to your .bashrc (or .zshrc if using zsh), replacing $(pwd) with absolute path to MXE installation.

Then, just go to DLL Solution folder and build it using build.sh:

./build.sh

Running Game Maker

To run Game Maker, go to Game Maker folder and type:

wine Game_Maker.exe

It is a good idea to keep unmarked "Hide the designer and wait while the game is running" under "File > Preferences" in Game Maker.

Running the Game "Headless"

Click here If you don't want to run all those steps manually.

In order to be able to train our bots, we should run the game "headless" (without showing graphics). Since SpelunkBots require to have a display, we can simulate one using Xvfb.

First of all, you need to have it installed.

In Debian based distros, we can install it using apt-get:

sudo apt-get install xvfb

Once xvfb is installed, we need to run a new display instance:

Xvfb :1 -screen 0 1024x720x24

This will create a new display (:1). Now, we just need to run spelunkbots.exe (this should be generated by GameMaker), specifying the target display:

DISPLAY=:1 wine /path/to/spelunkbots.exe

A simple way to debug (only to check if game is running) is to take a screenshot, it can be done by using import command (it is part of ImageMagick tools, so, you also need to install it to be able to take a screenshot):

DISPLAY=:1 import -window root /tmp/screenshot.png

We can also record a video using ffmpeg. Make sure you have it installed and run:

ffmpeg -y -video_size 1024x720 -framerate 30 -f x11grab -i :1.0 record.mp4

Runner Script

If you want to run all those steps automatically, please make sure you have the following dependencies installed:

Then, run the runner script (it is inside Source/spelunky_1_1) by doing this:

./run-headless.sh

You just need to make sure that you generated the spelunkbots.exe file.