This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.
(Reposted from my game development blog)
This is the gripping TRUE STORY of failed prototypes, wasted time, custom level editorsâ€¦ and UNEXPECTED SALVATION at the hands of the HUMBLE SPREADSHEET.
(Also it does literally have a recipe for creating a custom 2D level editor in like under a minute.)
A couple years ago, before beginning work onÂ Antihero, my current project, I was prototyping a 2D action game.*
When the core systems were in place, it was time to start building some test levels, so I got out my text editor and wrote some XML.
For obvious reasons, writing levels by hand is not a scalable process:
So my next step was to build an in-engine editor. I banged out a really basic one. Iâ€™d done this for a bunch of projects before, but even so, it took about 3 weeks, because I am slow.
It lacked basic features like undo/redo and copy/paste, it had bugs, and its UI was terrible compared to a â€śrealâ€ť tool like Unity, UnrealEd, etc - but at least it was better than hand-edited XML.
But! None of that matteredâ€¦ because a short while later I shelved the game. It was taking too long to find the fun, and no amount of editor fanciness was going to help.
So: onto the next prototype - another 2D game. (This one would eventually becomeÂ Antihero.)
With the core systems in place, it was again time to build some levels. This time, I was determined not to spend weeks on an editor for a game I might throw out anyway.
In the interest of ruthless efficiency, I scavenged for existing tools I might leverage. My goal was to write as little code as possible. It occurred to me that spreadsheets were 2D grids, so I pulled out Excel and fiddled with the cell layout a bit.
I picked a handful of symbols to represent game objects, designed a prototype level for my game, and spent a little while writing a script to convert CSV files into my XML level format.
Excel was immediately more useful than my previous custom editor. It has many of the qualities youâ€™d want: undo/redo, copy and paste, zoom in/out; and also some unexpectedly useful features, like find-and-replace, which I frequently used to count the number of a specific entity type. And itâ€™s fast and stable - andÂ reusable. (I reused all of this in a game jam a short while later - this time for a 2D platformer. Very different game; exact same editor.)
Of course, Antihero eventually outgrew its spreadsheet editor and grew its own custom big-kid editor on its way to eventual procedural level generation. But by the time the â€śrealâ€ť editor became necessary, the game design was much more solid, its important features were nailed down, and I knew it was a project with legs.
The code that parses CSV files is, as youâ€™d expect, trivial.Â You can get my Python script here.
This is the boilerplate for a custom editor using the csv_grid code from above:
The â€śeditor goes hereâ€ť game-specific bit is just a series of if-else statements that loops over the symbols in the grid, constructs aÂ representation of the board in the appropriate format -- in my case, XML --Â and prints it back out to the terminal, suitable for redirecting to a file. (You could also just write the CSV parser directly in your game and skip this intermediate step altogether.)
And thatâ€™s it!
There are good 2D editor tools out there, likeÂ Tiled. But if youâ€™re rapidly prototyping, it makes sense graduate to these - or a custom editor -Â afterÂ prototyping has proved out the core game.
* Thereâ€™s a lot of â€śborrowedâ€ť art in this postâ€™s screenshots. Thanks for not suing me, Binding of Isaac, Hero Academy, Warcraft 2, etc!