Zelda Dungeon Tiles

The Legend Of Zelda: Link’s Awakening is an action-adventure game for the original GameBoy. I wanted the tile sheets for the game’s dungeons so that I could make my own.

I found some maps assembled by Mister Mike

But there were problems. Firstly, they’re not tile sheets, they’re maps. Also they have 1 pixel padding between the rooms.

I wanted to crop the map, remove the padding, then isolate the unique tiles in order to stitch them into a sprite sheet. I used ImageMagick and Bash scripts.

First I made Bash scripts to help append images together horizontally or vertically.

if [ "$1" = "" ]; then
  echo "Usage: drag in images as parameters to append horizontally"
fi

convert "$@" +append "temp$RANDOM.png"
&2>/dev/null

Things to note:

  • I put a safety condition and helpful error if no input files are supplied as arguments.
  • I redirected all errors to the bin because they stop the rest of the script running. I’ll inspect the results if something goes wrong.
  • I name the output image with a random number to avoid overwriting it when the script is run again. With the +append command ImageMagick automatically resizes the “canvas” area to fit the last image added. Other commands require the +repage option to do this, otherwise the canvas either stays the same size as the first input image or creates an animated GIF.

This takes a dungeon map, crops it into rooms with padding along the top and left edges, removes the padding, leaving the 160x128 pixel rooms, then crops every room into 16x16 tiles.

convert $1 -crop 161x129 +repage c%03d.png
convert c* -crop +1+1 +repage b%03d.png
convert b* -crop 16x16 +repage a%04d.png
2>/dev/null

Some assumptions and preparation must be made. I reserved a folder for the intermediate images to avoid overwriting existing files, or selecting unwanted files that happen to be named “c001.png” etc. I cropped the source image to a regular size.

Issues

This process produces a lot of duplicates. For uncommon tiles I am sometimes better dipping into the map and grabbing the tile by hand. Some tiles are animated, but they appear in the sheet with padding around every frame.

convert $1 -crop 17x17 +repage a%01d.png && \
convert a* -crop +1+1 +repage b%01d.png && \
~/genIMAppendHorizontal.sh b*

I call my helper script from another script.

Stretch goals

Use Python image recognition to pick out only the unique tiles.
I think the primitive graphics might be suitable for this task since the sizes are regular, the patterns are consistent, the colours are few.