Westward dev log #4 : improvement of procedural tools

I’ve been almost fully back at work on the algorithms that I’ll use to eventually build the world for my game. As a reminder, a requirement for Westward is to have a very big world (“very big” still remains to be exactly defined), which calls for tools to automate the construction of that world.

More natural shapes

In a previous entry, I presented an algorithm to draw cliffs. The approach basically consisted in merging a bunch of rectangles and drawing along the contour of the resulting shape. While interesting, the result didn’t always look very natural. I have since written an entirely different algorithm to alleviate that problem. The new approach doesn’t rely on rectangles. Instead, it generates a random amount of alternating horizontal and vertical segments within a fixed area. The picture below illustrates a “mountain” created that way.

The result is more irregular, which is more convincing. An attentive eye might spot a few drawing “glitches” in some places, which is something I’ll come back to in the next section.

This image was captured at a 1:4 scale, to be able to show the whole mountain on-screen. The brown thingy in the top right of the picture is the player. The mountain spans several chunks of the map and would require some moving around to get to its other side. By adjusting two parameters (width and height of the covered area), a mountain 100 times that size (or less, or more) can be generated, without any more work on my part, which is the whole point.

In addition, the same shape-generating algorithm can be used to produce other natural bodies, such as lakes or patches of earth on the ground for example. It’s only a matter of painting different tiles on top of the produced shape. As this algorithm matures to produce increasingly more natural shapes, it is likely to become a cornerstone of my procedural world-building.

Apart from that, I have also been working on another kind of landscape element: rivers (and coastlines, which are basically one-sided rivers from the point of the view of the player). This is something I need much more control over, therefore I elected not to generate them randomly. Instead, I wrote a simple tool that allows me to click on the map, and which connects the points by drawing the appropriate tiles in-between. This still requires some improvements so I’ll show the results in a subsequent dev log.

The world-building pipeline

Most of the world-building takes place in the browser, where I use my custom tools. There, I can visualize the world map at multiple scales, and command the procedural tools by specifying a few parameters and the clicking on the map where they should appear. When I’m satisfied with the result, the changes are written to the files corresponding to the modified chunks of the map.

As you’ve seen in the above screenshot, the result is not always perfect. Some visual artifacts can appear, arising from the fact that the tileset I use and the shapes that are produced are not always 100% compatible. This will change in the future: on the one hand, I’ll perfect the algorithms, and on the other hand, I’ll eventually hire someone to make a tileset which is better suited for this. In the meantime, and also for the sake of giving life to the automatically generated environment, it’s important to be able to do manual fine-tuning.

For this, I use Tiled, which is a generic 2D tiled map editor. The great thing with Tiled is that it can read JSON files (provided they contain a few required fields), and write directly to JSON files as well. It makes the back-and-forth between the browser and Tiled extremely smooth. All the chunks of the map are stored in individual JSON files, which are loaded on the fly when playing the game. When I make changes in the browser, these changes are saved to these JSON files. The same files which Tiled can open directly. After I’m done in Tiled, the changes are again saved directly to the JSON files. There is absolutely no friction, and no need for conversions from one format to another. Everything is JSON.

The only requirement for this to work well is to have in mind how the JSON files need to be structured. Then, an empty world of arbitrary size can be automatically created, by generating the corresponding number of blank chunk files. Then the modifications can be applied, the broad strokes being automated with the browser tools, and the small strokes being manually applied in Tiled.

What’s next

I’ll be abroad for a few days, but I hope to be able to showcase in the next entry a full ecosystem of mountains, rivers, lakes an forests. It’s slowly getting there.

In parallel, I have been working a lot on the design document of the game. I’m getting an increasingly better view of what the different aspects of the gameplay will be and how they will interact together. I will be discussing some of them in future dev logs, but for the most part this is something that should be experienced, that’s why I’ll try to produce playable demos as soon as I can.

Jerome Renaux

I'm an independent game developer, working mainly on browser-based multiplayer online game (HTML5 & Javascript). I love to discuss about all aspects of game development so don't hesitate to get in touch!

More Posts

Follow Me:

Jerome Renaux

I'm an independent game developer, working mainly on browser-based multiplayer online game (HTML5 & Javascript). I love to discuss about all aspects of game development so don't hesitate to get in touch!