Best approach to make 2D grid levels visually

Godot Version

4.4.1

Question

I’m wondering what would be the best approach for my game (Forum link, and Itch.io) when it comes to building levels.

There’ll be a TL:DR at the bottom, but if you want the full context: I’m working on a Sokoban style game. Basically a 2d top down grid based puzzle game, where you push boxes around. In my case, into holes. Holes cannot be walked over, unless filled with a box. Simple stuff.

When I started this project I simply put an array of arrays in my level script to “draw” the map. 0 was void, 1 was floor, 2 was holes, 3 boxes, 4 the player. For example like so:

var level = [
	[0,0,0,0,0,0,0,0,0],
	[0,1,1,1,1,1,1,1,0],
	[0,1,4,1,1,3,2,1,0],
	[0,1,1,1,1,1,1,1,0],
	[0,0,0,0,0,0,0,0,0]
]

Which would in-game, be something like this:


(Void is black, green is the player, yellow the boxes, dark grey the holes, and light grey the floors)

That, as you can imagine, became tedious quickly, and hard to visualise when maps get more complex.

So I created a parser that takes an image. Like the one above, although that one is upscaled for visibility, but in reality every square is a pixel, so very small. This made creating levels much faster and worked well.

Until, I finished the basics of my game, and wanted to add new mechanics and complexities. For example a teleporter. One would be feasible, simple add 2 pixels of the same colour, and make them teleport to each other. But what if you add 2 teleporters (4 tiles)? In this case, there’s no way of knowing, from the image alone which tile should teleport where.

Surely, this can be fixed by using even more colours. Different colours for every different teleport. But that is not very scalable, and what if I later want to add pressure plates and doors? You get the idea, that won’t work long term.

Another solution I considered was supplementing the image with a file. For example some simple JSON to define some entities. For example like this:

{
  "teleports": [
    {"id": "A", "position": [3, 5], "connects_to": "B"},
    {"id": "B", "position": [8, 2], "connects_to": "A"}
  ],
  "pressure_plates": [
    {"position": [4, 6], "controls": ["door_1", "door_2"]}
  ],
  "doors": [
    {"id": "door_1", "position": [7, 3], "initially_open": false}
  ]
}

Like where teleports should be and to which they connect. And while that is a viable option, I don’t like it not being visual. It’s hard to make puzzles as it is, if then have to see the map, but mentally visualise from the JSON file where things are suppose to be, that’s going to be complex in larger maps.

A final solution I’m considering (After brainstorming with AI), is perhaps making a level builder in Godot. It’s starting to sound like the only feasible option the more I think about it. However, I’ve never done anything like that. So before I jump down that rabbit hole, I’m turning to you, the wonderful community, to perhaps give me a better suggestion on how to tackle this problem, or if there aren’t any, some great resources to build this tool.

Thanks for your time and answers in advance :raising_hands:.

TL:DR: What would be the easiest way to create levels visually for a grid based box pushing puzzler, with entities like teleporters, doors, keys, switches.

I’m a bit puzzled. Why don’t you just use the… editor itself? Or do you mean how to create a level editor inside your game?

1 Like

I am assuming there’s a feature I am unaware about, or are you suggesting I should drag in every cell (as scene) and position them by hand to build the levels?

No, you’re first direction was correct!

Yes, pretty much. You can use tilemaps for the most part. You could add custom fields in the tileset or add scenes as tiles for some basic elements. For switches, teleporters, doors, keys,… you can use scenes and @export variables to configure and connect them to other nodes if needed.

1 Like

Thanks for the links and info. That is exactly what I was looking for :raising_hands: