Gravity Beam: Master Gaiden Level Editing Documentation

12th April 2013

Making levels for Gravity Beam: Master Gaiden is hyper easy.


Tiled Map Editor

"Tiled is a general purpose tile map editor. It's built to be easy to use, yet flexible enough to work with varying game engines, whether your game is an RPG, platformer or Breakout clone. Tiled is free software and written in C++, using the Qt application framework."

I use Tiled to edit Gravity Beam: Master Gaiden and Gravity Beam levels. You can download it at mapeditor.org.

It has extremely easy importing of images, placement of objects and arbitrary polyline placement. It also has a very easy to understand interface, it works on any OS, and it's free!

Tiled project

I've included the Tiled project file (.tmx) for the built in GBMG level.

The level is a 64 megatile by 48 megatile map where the tiles are 16 pixels by 16 pixels. You can't have different sized levels without completely reassembling the game and ruining everything.

The map has only one layer: CanvasTiles.

CanvasTiles is a tile layer, holding the indices of the tiles that make up what you see of the level.

There is a single tileset using gaidentiles_uncollidableredattop_collidablebelow.png as the source image. You can resize the tile selector by holding CTRL and using the mousewheel.

The megatiles in the tileset are laid out in a specific way: tiles 15 and above are solid, tiles 14 and lower are passable. This distinction is hardcoded into the source in the collision checks for the player and box.

Megatiles

A megatile is a 16x16 pixel group of four 8x8 SMS graphic tiles. The file gaidentiles_uncollidableredattop_collidablebelow.png is a vertical strip of megatiles prepared for convenience for use with the Tiled editor. The actual file that's included in the game is a tile-reduced version of this prepared by Usenti.

I first drew all the graphics in their megatile form, making care to try and have repeating 8x8 subsections of tiles in preparation for tile creation. This check must be done manually, but you can repeatedly reduce tiles in Usenti to see if your changes have introduced new unique 8x8 tiles into the file.

When all the tiles were drawn, I used Usenti's 'Reduce Tiles' option to reduce the megatile strip into only unique 8x8 subtiles. This file is then converted to 4bpp and included into a Huffman archive.

To enable the game to select the appropriate 8x8 tiles when the camera pans over a megatile, the file megatiles_definitions.z80asm contains an array of [4byte] structures indicating what 8x8 tiles should be placed into the nametable for the given megatile. This is produced by 2013megatilemanager.exe (see the Gravity Beam: Master Gaiden Documentation file).

Exporting the level

Once you've laid out the tiles, it's time to export the level.

Go to File, Export As and export the map as a Json file. A Json file is a structured plaintext format that stores its data in a hierarchical key-value tree format. It's useful because it means we can use Javascript to parse the file and retrieve data by asking for what appears at a given path.

If we assign the Json object to the variable myjson, the three layers can be found at myjson.layers[n] where n is an integer. I iterate through values of n to find the layer with the right name. I could assume the positions of the layers in the Json file based on their positions in the Tiled layer stack, but they might not always end up in the same places.

The tile indices can be found at layer.data[] where layer.name == "CanvasTiles". The tile indices are 1-based rather than 0-based though.

Converting the level

json_to_ascii_gaiden.htm is a HTML file containing a Javascript script that reads the Json tree from var myjson and produces copy-pasteable HTML output that can be further processed to make the level. It gets the tileset data and makes it zero-based to match how the game executable expects it.

To use json_to_ascii_gaiden.htm, copy the complete contents of your exported Json file at the top as var mysjon = {.... Then save it and open the file in a web browser. The output should appear as a plaintext list similar to the following:

; Level tile map data follows.

        dc.b     0, 0, 0, 0, 0, 0, 0, 0, 0, 0...

This text is a series of WLA-DX compatible data declarations defining the tilemap indices for your level. You should be able to see your level reflected in the layout of the numbers. Then you can copy this text from the browser window into a .z80asm file and use WLA-DX to convert it into a block of binary data. Gravity Beam: Master Gaiden expects the level data to be compressed, so place levellayout_megatiles.bin into the directory huffman_archives.

The starting and ending positions of the player and box are hard coded in the .z80asm source, as the game was designed for this level specifically. This also means that if you want to have a different goal than dragging the box out of the top of the level, you'll have to program that in yourself.

Once you've got your .bin compressed and the positions re-coded, assemble and link the game, and everything should be fine!