-
Notifications
You must be signed in to change notification settings - Fork 806
Edit the Town Map
The Town Map is a bit tricky to edit: it's one of the only things in pokecrystal that still requires a hex editor. This tutorial will explain how it works.
Like everything else on the GameBoy, the Town Map is composed of 8x8-pixel tiles. Its tile graphics are stored in gfx/pokegear/town_map.png:
You can freely edit this image to change the tiles, but you can't make it larger. That's because all the available tileset space is taken up by Pokégear and font graphics. You can see this in BGB's VRAM viewer:
(For adding more tiles, there are those three unused blank ones on the right side of the tileset.)
The two regions' maps are actually defined by gfx/pokegear/johto.bin and gfx/pokegear/kanto.bin. Each of those is a 361-byte binary tilemap: 20x18 bytes covering the entire screen, from top-left to bottom-right, with a $FF at the very end. The bytes are tile IDs, starting at 0. For example, $0A (10 in decimal) is the eleventh tile in the tilemap, the town or city icon. And if you look at where the $0A bytes are in johto.bin and kanto.bin, you'll notice they correspond to the locations of towns and cities.
If your hex editor supports coloring by value, that can make editing a lot easier. For example, here's Hex Workshop (not a free program) using a custom color map to highlight different tile IDs:
Clearly, those bytes represent these Town Maps:
Landmarks are defined in data/maps/landmarks.asm. Each one has an X coordinate, Y coordinate, and name. The coordinates are in pixels from the top-left corner, but with 8 added to X and 16 added to Y. For example:
landmark 148, 116, NewBarkTownName
...
NewBarkTownName: db "NEW BARK¯TOWN@"
148 − 8 = 140 and 116 − 16 = 100; and if you look at pixel coordinates (140, 100) in the Johto map above, you'll see it's in the middle of the New Bark Town icon.
If you're wondering why those offsets exist, it's because of how the GameBoy hardware works. From the Pan Docs:
Byte0 - Y Position
Specifies the sprites vertical position on the screen (minus 16).
An offscreen value (for example, Y=0 or Y>=160) hides the sprite.Byte1 - X Position
Specifies the sprites horizontal position on the screen (minus 8).
An offscreen value (X=0 or X>=168) hides the sprite, but the sprite
still affects the priority ordering - a better way to hide a sprite is to set its Y-coordinate offscreen.
For more information on editing landmarks, see the tutorial on how to add a new map and landmark.