Archive for the ‘libtcod’ Tag
A scrolling demo (a roguelike in Python #2)
So after making a simple @ walking demo with libtcod, I took a look at it again and thought, you know what would make this cooler? If the map scrolled! Yes — scrolling is cool, and I had never written a scrolling viewport, so my plans were set.
Now there are many scrolling tutorials out there (I usually look at Tony Pa’s for inspiration) and the theory is simple. Instead of drawing the entire map and its contents to the window (as I did in the first demo), you create a frame — sometimes called a frame, viewport, or camera — which the map ’scrolls’ under.

So instead of each coordinate on the map corresponding exactly with the same coordinates in the window, the correspondence between the map coordinates and the window coordinates will change as your viewpoint (for my purposes, the location of the @ character) moves around the map.
In simple terms, the @ is always in the center of the window — it is the map contents which ’slide’ under the @ as it moves. So it is logical to ask what happens when the @ gets to the edge of the map. You have two basic choices in this situation — one, keep the @ in the center of the viewport window, and make anything ‘off-map’ a frame color or texture (for example, like when you dynamically resize a web page by making the browser window wider or narrower); and two, allow the @ to go to the edge of the window when it comes close to the edge of the map. Of course, the latter option is much better looking, so the choice is clear there. There are no compromises made on this blog.
So on to the code — I won’t post it all, as the imports, utility functions, game state update, and main loop are still the same.
How to write a roguelike in Python using libtcod (#1)
I’ve known about the libtcod roguelike library for a while, mainly through the Python port in development by Kyle Stewart. However that project seemed to be in stasis. Then just a week or so ago I looked at libtcod again, because of some beautiful roguelikes that are using the C/C++ version of the library.

Pretty amazing, no? And that’s all textmode!
So it turns out, in the meantime the developer jice created a Python wrapper and some Python samples to go with it. From there it was quite easy to use the samples as a base for a simple ‘get your @ on the screen moving around’ demo.

Comments (1)
Comments (4)
Subscribe to Kooneiform



