There is a story I remember reading from years and years ago that really resonated with me as a developer. In this story, which was from the original PlayStation era, a bunch of developers started cheering excitedly while crowded around a TV. Someone that isn’t a developer wanders over to see what all the hubbub is about and is surprised to see a single black triangle on the screen. They ask what the big deal is because it doesn’t seem like the sort of thing that should be so exciting. Afterall, it’s just a single triangle on an otherwise blank screen. The developers explain that it represents that after months of work they have finally finished the pipeline that gets that triangle on the screen. The data structures, the code that talks to the PlayStation hardware, the thing that places the triangle on the screen, it was all there and it was all working. It represents the point where they have enough underlying work done to be able to start really working on the game they were trying to make. As the story goes, they had complex 3D models on the screen later that same day and went on to create games like Twisted Metal and Jet Moto.

I had a similar moment last night when I hit the run button to check out a part of my game and the screen that came up was the same as it used to be. No outside observer would have guessed that this lack of change represented something like 4 days of work and planning. The system I’m trying to build is the underpinnings for the entire game. Generate the world using tiles. Sounds simple right?

I had to build a series of data structures that represent the world in the game. They are a nested structure that starts at the top by representing the whole world. Under that, is a collection of rooms that are the places the player will run around in. Rooms are built up using structures which can be anything at all from walls and the ceiling to a floating platform with a statue on it. The structures are made up of tiles of graphics, each obviously made up of pixels. Once that was planned out, I started building a similar nested structure of generators for generating the world, rooms, and structures. There will be a single world generator for orchestrating everything, but dozens of room generators that each understand different kinds of rooms and probably hundreds of structure generators. The graphics tiles are not generated by this system they are hand created and only stitched together into the world.

For that to work, there are another pile of data structures needed to represent the tiles. What starts its life as a simple .PNG file, needs to be loaded into Godot as a TileSet. In a normal game, the next step would be to draw the world by hand in the editor and since a person would be doing that, they can figure out on their own which tiles are used for which things in the world. Unfortunately, because my entire world is randomly generated using all the generators described above it all sort of falls away from human intuition and understanding. My code needs to understand the exact purpose of every tile, how to use them, and where they are in the TileSet. This brings with it more data structures that my code can use to figure all of this out. That meant JSON data, the code structures it gets loaded into, and the code that uses that information to figure out what draw. Stick it together with what feels like an unending amount of glue logic and you’ve really got something.

I had created a scene called WorldDebug for the purpose of seeing the things I was generating so I could figure out if they were wrong and fix them. Before last night I was hard coding things and using Godot’s custom line drawing features to imitate the developer art tiles I’d made. It didn’t take long before I realized this approach, which was originally just supposed to give me enough information to ensure my generators were making the right things, was turning into a massive amount of duplicated effort. Specifically, I’d made real graphics tiles already, and now I was coding things to imitate them with line drawing techniques. I knew I needed to stop that because it was a waste of time.

Last night, I hit run on the heavily modified WorldDebug scene. It now fires up the world generator, creates a single room, and adds structures to it representing the floor, ceiling, and both walls, loads a PNG as a TileSet, loads JSON to define how it’s laid out, walks the generated structures and draws the world on the screen using tile graphics cut out of the TileSet. The picture it created was the exact same as when I was using line drawing. I was genuinely excited about the total lack of change for a screen I had already.

It’s hard to explain how much work this change was. Since I didn’t need to waste a ton of time faking graphics with line drawing techniques anymore I knew it would save a ton of time in the long run. Better still, the structures and code I’ve made for this can be used for building the TileMaps that will actually run the game, and can be used for creating the in-game mapping system too.

If you’re interested in the original Black Triangles story, it can be found on the Rampant Games blog.