The Invent with Python Blog

Writings from the author of Automate the Boring Stuff.

Mon 10 December 2012

8-bit NES Legend of Zelda Map Data

Posted by Al Sweigart in pygame   

I've created Python & Pygame script that lets you walk around the overworld map of the original Legend of Zelda game on the 8-bit Nintendo. There are no monsters or levels or items; it is simply a walking tour. The Link walking sprite animation is implemented by my Pyganim module.

More importantly, this program does provide the raw map data the entire world map (something I haven't been able to find on the web.) Getting this from the Zelda ROM is actually a pain due to the tricks used to store the map info. The game doesn't store individual tiles and their XY location, but rather have one of three color schemes for the border and a color scheme for the center tiles. Even then, the game only stores columns of tiles, and then each room references which columns it uses. (You can notice the same columns being used in different rooms, even though their color scheme may change.)

These tricks aren't really needed with today's computers for a game as simple as Zelda, so I've compiled the tile map data for each individual location on the map. Here's the world map data file (it is also included in the main download below.)

Download the Zelda Walking Tour program.

View raw tile map data.

(Just unzip all the files and run the file with Python. Runs with both Python 2 and Python 3. Requires the Pygame module to be installed.)

You can also download the code from the GitHub project.

Blocking is not implemented, which means you can freely walk through walls. The tiles are stored in overworldtiles.png:

To find which tiles correspond to the hex numbers in the world map data file, use this key (the numbers start at 0 and simply increasing going to the right):

And just for grins, I have a pixel-perfect single image of the entire world map, without enemies or anything else polluting it. The colors may be a bit off from the actual game, but they are consistent:

If you'd like to work on a similar project to this, here's a good page I've found that I wish I had seen before I started: More GPU Tile map demos (Zelda)

Some general stats about the NES Zelda map data:

  • The entire overworld is 4096 x 1344 pixels, 16 x 8 rooms, and 256 x 88 tiles in size.
  • Each room (a single screen) is 16 x 11 tiles in size (the bottom row only shows the top half of the tile). It is 256 x 176 pixels in size (if you count the bottom half of the bottom row).
  • Each tile, including Link himself, is 16 x 16 pixels in size.
  • There are seven colors used on the overworld map (though the RGB values may not be perfect):
    • (32, 56, 236)  blue
    • (252, 252, 252)  white
    • (200, 76, 12)  brown
    • (0, 168, 0)  green
    • (116, 116, 116)  gray
    • (252, 216, 168)  tan
    • (0, 0, 0)  black

Learn to program for free with my books for beginners:

Sign up for my "Automate the Boring Stuff with Python" online course with this discount link.