Complete Roguelike Tutorial, using python3+libtcod, part 0
Setting it up
Ok, now that we got that out of our way let's get our hands dirty!
Windows
Python
If you haven't already done so, download and install Python 2.7. Any version of Python 2, from 2.6 and above should be fine, but the latest update (of Python 2, not Python 3) is of course always preferable.
There are reports that for older versions of libtcod on 64-bit Windows (Windows 7) that the 32 bit version is preferable, since the 64 bit version of Python seems to cause problems with libtcod. This was been tested on Windows 10 with libtcod 1.6, and was not reproducible, so it's up to you.
It might be advisable to go with 32 bit just to keep things simple, and when you're gone through the tutorial look at switching to 64 bit if it matters to you to do so, and if you do encounter errors specifically related to this, report them on the libtcod bug tracker.
libtcod
Download the latest release of libtcod 1.6 and extract it somewhere. Be warned that both Python and libtcod must either be both 32 bit, or both 64 bit. If you get dll loading errors, getting this wrong is the most likely cause. libtcod will now (as of 1.6.2 and above) check they are compatible, and tell you if they are not.
Check if libtcod works
libtcod is compiled with the latest official release of Visual Studio. In an ideal world, it should just run, and if you have recently updated games installed from Steam or perhaps even some modern applications, it should. However, some people lack the support for that latest release of Visual Studio, and these steps help update your computer to allow libtcod to be run.
- Within the libtcod release you just extracted, you will see a file called samples.exe.
- Run samples.exe and verify that it appears to work. If it opens a colourful window, then it is now verified as working for you.
- If it just doesn't start and instead you see a message about vcruntime140.dll being required, then you need to install the correct Visual Studio 2015 runtime.
- Go to the latest Microsoft Visual Studio 2015 runtime download page, and download and install the runtime that matches the Python and libtcod you are using. If you are using 32 bit Python and libtcod, this will be the x86 runtime. If you are using the 64 bit Python and libtcod, this will be the x64 runtime. (Tip: If you think you might switch from 32 bit to 64 bit in the future, hedge your bets and install both runtimes to prevent future problems.)
- Once you've installed the correct runtime, run samples.exe and verify that it now appears to work. If it still gives the same message, you didn't install the correct runtime. If it opens a colourful window, then it is now verified as working for you.
- If it is not verified as working for you, you can open a libtcod bug report on BitBucket.
You've verified that libtcod is working? Great! You can move onto the next section.
Your project folder
Now create your project's folder. Inside it, create an empty file with a name of your choice. We're using firstrl.py. It'll make the tutorial easier to just use the same name, and you can always rename it later.
From within the libtcod build you downloaded above, select and copy the relevant DLLs.
From within the libtcod build you downloaded above, select and copy the libtcodpy folder.
From within the libtcod build you downloaded above, select and copy the arial10x10.png font. If you choose a different one, you'll need to adjust how you do the tutorial accordingly. It's simpler to just use the same one as we do, and change it later, if it suits you to do so.
At this point, you should have a folder that looks like this:
You're ready to start editing firstrl.py!
Autotools platforms (Linux, MacOS, ...)
Python
The tutorial is written for Python 2, so ensure you have it installed and know what it is called.
SDL2
If your OS or OS distribution has a package that can be used for SDL2 development, then the best option is to install it. This will ensure that you can easily update it.
In the event that you cannot find a package, you can compile it yourself as a last resort. To do so, download the supported SDL2 revision, build and install it:
$ curl -o sdl.tar.gz http://hg.libsdl.org/SDL/archive/007dfe83abf8.tar.gz
$ tar -xf sdl.tar.gz
$ cd SDL-007dfe83abf8/
$ mkdir -p build
$ cd build
$ ../configure
$ make
$ sudo make install
This will place the libraries at `/usr/local/lib/` and the development headers at `/usr/local/include/SDL2/`.
libtcod
Download the latest libtcod release and compile it:
$ wget https://bitbucket.org/libtcod/libtcod/downloads/20161228-libtcod-1.6.2.tbz2
$ tar xf 20161228-libtcod-1.6.2.tbz2
$ cd 20161228-libtcod-1.6.2
$ cd build/autotools/
$ autoreconf -i
$ ./configure
$ make
$ cd ../..
Now you should be in the root libtcod directory. You can see the compiled library like:
$ find . -name "libtcod.so"
./build/autotools/.libs/libtcod.so
However, notice this .so is actually a link to this other .so.0.0.0 file in the same directory:
$ readlink ./build/autotools/.libs/libtcod.so
libtcod.so.0.0.0
Your project folder
Now you're ready to make a directory for your new project, copy the compiled library and links, plus the python library and a font into it:
$ mkdir -p ~/tutorial
$ cp -dr build/autotools/.libs/libtcod.so* python/libtcodpy data/fonts/arial10x10.png ~/tutorial/
$ cd ~/tutorial
You should be able to see something similar to this:
$ ls -lgo
total 1388
-rw-rw-r-- 1 14870 Dec 31 15:57 arial10x10.png
drwxrwxr-x 2 4096 Dec 31 15:57 libtcodpy
lrwxrwxrwx 1 16 Dec 31 15:57 libtcod.so -> libtcod.so.0.0.0
lrwxrwxrwx 1 16 Dec 31 15:57 libtcod.so.0 -> libtcod.so.0.0.0
-rwxrwxr-x 1 1413856 Dec 31 15:57 libtcod.so.0.0.0
Now you're ready to start.