#002 Detours in the game development


Detours in the game development 🚧

Version 1.0.10 of SSiS was released about 2 weeks ago and I’m still working on the next big version. A lot of changes are coming along the way. I’ve been busy with it since the beginning of August and the level of complication has grown to the point where I needed to change my approach to the development process. So far, the whole game logic (characters, items, maps, quest, translations, UI layout, ASCII art) was stored in a separate json file. I like this separation from the game engine since I can change the gameplay without changing the code. Actually, after starting the game, it will try to fetch a new version of this config.json from the server and update the local copy. This is super convenient since I can upload spelling fixes and do some game balancing on a live version.

But, as I mentioned, the game started to expand, and the json file became huge (5K lines 🤯) and it is now very difficult to maintain. I tried to apply json schema for validation, but at this point it was too late. The structure of my json was very irregular and making it tidy would require a massive refactoring of the game engine. I mean, json schema is super helpful, there are many good Python 🐍 implementations and there are even online tools that try to generate a schema from existing json file. When you have a proper schema in place, VS Code supports it very well and will alert you when you’re not obeying the rules. But, as I said, it was too late for me. If only I knew about it earlier…

So, I decided to take a small detour 🚧 from developing the main game and… started building a separate tool to master the json file. I called it the Config Editor (very original, isn’t it? 🤓). Never mind the name, what is really important is that I’ve taken on the challenge to write it using the Textual library. This library is so amazing and powerful that I will definitely write a separate devlog about it one day. For now, I’ll just say that it’s a library for building terminal-based UIs that look like GUI but don’t require any windowing system. I just love it 💓. For context: my game engine is written using rich - a predecessor of Textual so to speak, by the same author. Rich is also very powerful and also more mature (Textual is still in intensive development). Rich is more low-level, without the support for keyboard and mouse events unfortunately for my game. I’m struggling with it a lot. Eventually, I’ll migrate to Textual completely, but this is again… yes, you guessed it - a massive refactor of the game engine (I clearly have an issue with doing refactoring 🤭).

Writing Config Editor using Textual was for me a good way to learn this library, and see its full potential (not so obvious at the beginning), but it also had some shortcomings. At least for the purpose of a roguelike RPG game engine running in the terminal. Boy, this was a huge detour from writing the game itself. For the whole of August, I made zero progress in SSiS and only managed to create screens to edit some of the most important config options. Writing a nice UI, using CSS (yes - a terminal-based app is using internally a subset of CSS to customize the look and feel) is not one of my specializations. Oh, I never was good at CSS, and now I had to learn it again 🙈. I went 2 or 3 times through a serious crisis of faith, and I was thinking about giving up on this tool and going back to plain json. Even now, there are parts that look ugly, but since they work, I’m not touching them for now so I can move forward.

Things started to get in shape when I started to work on maps 😬. You see, so far, I’ve been drawing my maps using text editor. This looks something like this:

............,,,,,,,,,,,,,,,,,,#
..ij&.......,,,ojj,,,,,,,,,,,,#
.iFj........,,,j,j,,,,,,,,,,,,#
..ijj!......jjjjjjjj,,,,,,,,,,#
............j......j,,,,,,,,,,#
..........jjjjjG5*.j,,,,,,,,,,#
wwwwwwww..j...j...jjjj........#
wwbswsss=jj.jjj.jjj..jj.......#
wwwswwwsw.j.jŁj.jOj...j.......#
wssssswsw.jjjjjjjjj..llll.....#
wswwwswsw.j..j......ll~~ll....# E exit
wss8wsssSjcjjjj.jjjll~~~~ŁjEM.# 
wswwwwwsw./...jjj..l~~~~~~t~~~#
wswwssssw.j.....j..ll~~~~OllM.#
wssswswsw.^.....jj..lf~~ll.LM.# ^ start
wswssswsw........jj..Zlll.....#
wswwwwwVw.........jjj.TgT.....#
w?wwwwwww.............TvT.....#
wwwwwwwww.............TTT.....#

Each symbol is then mapped to a wall emoji, location name, item, character, stairs, etc. The final map looks like this:

I did use some aid form tools like asciiflow, but it is a very tedious work. This is why my current maps are so small.

I did some reading, and apparently, orthodox roguelike games use only automatically generated maps. Some of them are then manually fine-tuned and do not change each time you restart the game, but the majority are generated on the fly. This is why they can have huge maps. I’m more inclined to generate big, natural-looking maps and then hand-tune them.

The problem ⛔

The art of procedurally generated maps got me possessed for several weeks. I watch hours of talks from GDC and others on YouTube. This combination of art and science is so fascinating. You seen, it takes much more than a random number generator to create a nice map. Everyone, with a single glance, can tell if a map looks realistic, credible, and beautiful at the same time. But putting it into a set of rules, that can be implemented in a computer program is a different story. Map generated automatically not only needs to look good and feel organic, but the algorithm needs to fulfill some practical requirements: there should be a way to generate the same base map many times (for reproducibility), but also give some parameters to fine-tune other aspects of the map (e.g. roughness).

I’ve learned about:

The cure 💊

This brought me to yet another detour 🚧 from the base game development - I decided to take part of my Config Editor responsible for map generation using diamond square and release it as an open-source, stand-alone library:

tui-map-generator - released just today 🎉

Here is an example of a map generated using it:

maps/example_01.png

I’m really satisfied with the results - I hope it will be useful for others. There is more information about how it works in the README file. For those interested in the algorithm, here is the link project and YouTube video that inspired me to write it:

Summary 📝

That’s all for today. This one is longer than I expected 🙈. I hope it wasn’t boring.

Get inspired 💡, share 📣 and create 🏗️!

Get SSiS

Leave a comment

Log in with itch.io to leave a comment.