Difference between revisions of "Complete Roguelike Tutorial, using python3+libtcod, setup Windows"

From RogueBasin
Jump to navigation Jump to search
(Created page with "first edit")
 
Line 1: Line 1:
first edit
==== Python ====
 
If you haven't already done so, [http://www.python.org/download/ download and install Python 3.6]. Any version of Python 3, from 3.6 and above should be fine, but the latest update (of <i>Python 3</i>, not Python 2) 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 [https://bitbucket.org/libtcod/libtcod/issues/ libtcod bug tracker].
 
==== libtcod ====
 
Download the latest release of [https://bitbucket.org/libtcod/libtcod/downloads libtcod 1.6] and extract it somewhere. Be warned that both Python and libtcod must either be <b>both 32 bit</b>, or <b>both 64 bit</b>.  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.
 
<ol>
<li>Within the libtcod release you just extracted, you will see a file called <cite>samples.exe</cite>.</li>
<li>Run <cite>samples.exe</cite> and verify that it appears to work.  If it opens a colourful window, then it is now verified as working for you.</li>
<li>If it just doesn't start and instead you see a message about <cite>vcruntime140.dll</cite> being required, then you need to install the correct Visual Studio 2015 runtime.</li>
<li>Go to the latest Microsoft Visual Studio 2015 [https://www.microsoft.com/en-us/download/details.aspx?id=53587 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.)</li>
<li>Once you've installed the correct runtime, run <cite>samples.exe</cite> 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.</li>
<li>If it is not verified as working for you, you can open a libtcod bug report [https://bitbucket.org/libtcod/libtcod/issues?status=new&status=open on BitBucket].
</ol>
 
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.
 
[[File:Windows-01-162-project-folder-empty.png|center]]
 
From within the libtcod build you downloaded above, select and copy the relevant DLLs.
 
[[File:Windows-02-162-dlls.png|center]]
 
From within the libtcod build you downloaded above, select and copy the ''libtcodpy'' folder.
 
[[File:Windows-03-162-libtcodpy-folder.png|center]]
 
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.
 
[[File:Windows-04-162-font.png|center]]
 
At this point, you should have a folder that looks like this:
 
[[File:Windows-05-162-project-folder-ready.png|center]]
 
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:
 
<syntaxhighlight lang="bash">
$ 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
</syntaxhighlight>
 
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:
 
<syntaxhighlight lang="bash">
$ 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 ../..
</syntaxhighlight>
 
Now you should be in the root libtcod directory. You can see the compiled library like:
 
<syntaxhighlight lang="bash">
$ find . -name "libtcod.so"
./build/autotools/.libs/libtcod.so
</syntaxhighlight>
 
However, notice this .so is actually a link to this other .so.0.0.0 file in the same directory:
 
<syntaxhighlight lang="bash">
$ readlink ./build/autotools/.libs/libtcod.so
libtcod.so.0.0.0
</syntaxhighlight>
 
==== 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:
 
<syntaxhighlight lang="bash">
$ mkdir -p ~/tutorial
$ cp -dr build/autotools/.libs/libtcod.so* python/libtcodpy data/fonts/arial10x10.png ~/tutorial/
$ cd ~/tutorial
</syntaxhighlight>
 
You should be able to see something similar to this:
 
<syntaxhighlight lang="bash">
$ 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
</syntaxhighlight>
 
Now you're ready to [[Complete Roguelike Tutorial, using python3+libtcod, part 1|start writing code]].

Revision as of 17:23, 14 September 2017

Python

If you haven't already done so, download and install Python 3.6. Any version of Python 3, from 3.6 and above should be fine, but the latest update (of Python 3, not Python 2) 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.

  1. Within the libtcod release you just extracted, you will see a file called samples.exe.
  2. 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.
  3. 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.
  4. 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.)
  5. 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.
  6. 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.

Windows-01-162-project-folder-empty.png

From within the libtcod build you downloaded above, select and copy the relevant DLLs.

Windows-02-162-dlls.png

From within the libtcod build you downloaded above, select and copy the libtcodpy folder.

Windows-03-162-libtcodpy-folder.png

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.

Windows-04-162-font.png

At this point, you should have a folder that looks like this:

Windows-05-162-project-folder-ready.png

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 writing code.