Turnament Devlog Nr. 23 - Building the Level Editor


In 2006, my friend Darrn and I were taking a walk through the outskirts of Linz. We talked about games, and he said he played Turnament (my latest game release after Phabetal). He liked it, but he also said to me: "How about a level editor?"

And in my mind I was like, no way I want to do this in a small flash game. Sure, seeing what other people would create with it sounds interesting, but the launch was behind me, and in my mind it was hard to get people to put eyes on it again.

So here I am, 17 years later, and I want to have a level editor for Turnament. On launch day.

How?

I decided to start small: I wanted to be able to select an object in the menu, and then place that object wherever my cursor was.

So far, so good! Next, I wanted to add more objects. Crystals and seekers. There's no limit yet to how many seekers you can build, so - with the seeker eye following the cursor - it looked like this:

Without worrying too much about performance just yet (it was horrible), I continued implementing each object, one after another, including broken squares, which required a different setting.

I also added asteroids, shields, creators, projectiles. And a way to select different types of asteroids by clicking on the asteroid button again.

Then, it was time for...

Play Mode

I wrote code that parsed all built objects into JSON format, and then created a function that constructed a level from any given JSON.

With some adjustments to the game manager, I was then able to switch between editing and playing. And it felt really good!

At this point I was also able to select objects with numbers on the keyboard for quick access.

The next challenge was saving and loading. I already had the JSON format, so all I needed to do was to adjust the storage manager (which handles the savegame) and - it was done! Loading a level required me to show a level selection to the player, and I thought I'd use a similar selection to the campaign level selection, with the difference that you can basically build your own campaign (if you wanted to).

Entering Hell

The biggest and possibly most painful feature to implement - and the final piece of the puzzle - was a way to edit specific object settings.

A creator can shoot in different directions, clockwise directions, change initial delay, or interval between shots. A creator can move from point A to point B, or move around randomly. The same goes for a creator's projectiles. And seekers need an option to set whether it's a regular or a repair seeker.

I slowly found a way to make it work with my current UI system by adjusting UIButtons to also have values that can be changed. I implemented the shot direction and the "random direction" boolean and...

After a week, it finally worked!

Settings got saved and loaded with dynamically generated buttons. And these settings also got saved in the level's JSON file, as well as safely restored upon loading the level and clicking on the respective object.

The battle was not over just yet. The interval between shots required a numeral value. The target position for patrolling needed to be set in a convenient way. In total I needed another dozen settings. And all this without exploding the UI popup.

Well... The popup exploded.

The patrol targets spawn a new menu with a semi-transparent button, which lets you select a position on the grid with convenience.

Lots of smaller bugs in the UI code got squashed along the way. This popup alone took me another week.

With the creator settings complete, it was time to create separate settings for projectiles and seekers, which was now extremely easy.

I still wanted to add some polish to this menu and a visible trail for the position selection, but it would have to wait for another time.

For now, I'm happy that this chunk of code is complete. It was in my head for almost a month now and frankly, it blocked me from doing other stuff (like music).

All in all, I can finally say that the level editor is real 🔨

To be continued... 💎