You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -29,10 +33,16 @@ From here it is time to setup a ``tcod`` program.
29
33
Download `Alloy_curses_12x12.png <https://raw.githubusercontent.com/HexDecimal/python-tcod-tutorial-2023/6b69bf9b5531963a0e5f09f9d8fe72a4001d4881/data/Alloy_curses_12x12.png>`_ [#tileset]_ and place this file in your projects ``data/`` directory.
30
34
This tileset is from the `Dwarf Fortress tileset repository <https://dwarffortresswiki.org/index.php/DF2014:Tileset_repository>`_.
31
35
These kinds of tilesets are always loaded with :python:`columns=16, rows=16, charmap=tcod.tileset.CHARMAP_CP437`.
36
+
Use the string :python:`"data/Alloy_curses_12x12.png"` to refer to the path of the tileset. [#why_not_pathlib]_
37
+
38
+
Load the tileset with :any:`tcod.tileset.load_tilesheet`.
39
+
Then pass the tileset to :any:`tcod.context.new`, you only need to provide the ``tileset`` parameter.
32
40
33
-
Load the tileset with :any:`tcod.tileset.load_tilesheet` and then pass it to :any:`tcod.context.new`.
34
-
These functions are part of modules which have not been imported yet, so new imports need to be added.
35
-
:any:`tcod.context.new` returns a :any:`Context` which is used with the ``with`` statement.
41
+
:any:`tcod.context.new` returns a :any:`Context` which will be used with Python's :python:`with` statement.
42
+
We want to keep the name of the context, so use the syntax: :python:`with tcod.context.new(tileset=tileset) as context:`.
43
+
The new block can't be empty, so add :python:`pass` to the with statement body.
44
+
45
+
These functions are part of modules which have not been imported yet, so new imports for ``tcod.context`` and ``tcod.tileset`` must be added to the top of the script.
36
46
37
47
.. code-block:: python
38
48
:emphasize-lines: 2,3,8-12
@@ -54,7 +64,7 @@ These functions are part of modules which have not been imported yet, so new imp
54
64
If an import fails that means you do not have ``tcod`` installed on the Python environment you just used to run the script.
55
65
If you use an IDE then make sure the Python environment it is using is correct and then run :shell:`pip install tcod` from the shell terminal within that IDE.
56
66
57
-
If you run this script now then a window will open and then immediately close.
67
+
There is no game loop, so if you run this script now then a window will open and then immediately close.
58
68
If that happens without seeing a traceback in your terminal then the script is correct.
59
69
60
70
Configuring an event loop
@@ -241,6 +251,11 @@ You can review the part-1 source code `here <https://github.com/HexDecimal/pytho
241
251
.. [#tileset] The choice of tileset came down to what looked nice while also being square.
242
252
Other options such as using a BDF font were considered, but in the end this tutorial won't go too much into Unicode.
243
253
254
+
.. [#why_not_pathlib]
255
+
:any:`pathlib` is not used because this example is too simple for that.
256
+
The working directory will be the project root folder for the entire tutorial, including distributions.
257
+
:any:`pathlib` will be used later for saved games and configuration directories, and not for static data.
258
+
244
259
.. [#init_context] This tutorial follows the setup for a fixed-size console.
245
260
The alternatives shown in :ref:`getting-started` are outside the scope of this tutorial.
0 commit comments