(Godot) Map

Published on July 7, 2018.

Quebec has been going through a heatwave. Yesterday was the only reprieve we’ve had. It looks like it’ll last well into the upcoming week. I always have motivation issues when the heat beats on me. I hope all my fellow Quebecers are keeping cool! I did managed to advance a bit on exploration gameplay.

Tile-Based Terrain Creation

I started the week reversing my terrain creation algorithm. Previously, my algorithm ran a few rules to add trees, rocks and rabbits, after creating the nine tiles around the player character. The further tiles ended up with varying heights, but empty of trees and rocks. I’ve moved all this code in a new TerrainBuilder class. Its purpose is to create terrain tiles, on demand, and fill them with interesting details. Eventually, I’ll probably need a TerrainRecycler class to go along!

Interesting Terrain

I was roaming in my improved terrain and I had a few questions that I could not answer. How realistic does the terrain look? How will this terrain scale further? How can I make this terrain interesting after having explored a dozen tiles?

I spent some time pondering on the solution. I came across the Azgaar Fantasy Map Generator. I was pretty inspired by it. I want to prototype mixing very-high level elements with low-level/per-tile elements, in order to create an interesting terrain that a player would enjoy discovering and exploring.

Map

I knew that to work on a more complex terrain generation algorithm, I had to implement a map user interface. This is a screenshot of my work-in-progress, it shows a few buttons to select a map-mode on the left. The currently-selected map-mode shows the terrain heights. From this level, the Simplex noise function really shows through!

Adding this new UI to my godot project was straight-forward. The only pitfall that I encountered was when creating the image, procedurally, in the C++ code. I’ve been mostly treating the Godot’s rendering engine has a black-box, so I made quite a few attempts before finding the proper way to procedurally create an image and draw it on the screen. The following C++ code creates the procedural image. This image is received by the Godot Script and then fed into a TextureRect control.

    PoolByteArray image_data;
    image_data.resize(width * height * 16);
    {
        PoolByteArray::Write writor = image_data.write();
        Color *bits = reinterpret_cast<Color *>(writor.ptr());
        for (int y = 0; y < height; ++y) {
            for (int x = 0; x < width; ++x) {
                (*bits) = Color(R, G, B);
                bits++;
            }
        }
    }

    Ref<Image> image;
    image.instance();
    image->create(width, height, false, Image::FORMAT_RGBAF, image_data);

    Ref<ImageTexture> output;
    output.instance();
    output->create_from_image(image, 0); // 0 -> no filtering, clamping, no mip-maps.
    return output;