# Need some advice for tilemap design

## Recommended Posts

beaner    100
Wasn't sure where exactly to address this, so I put it here... I am designing a 2D tile engine that is very similar to Super Metroid. I want to treat each individual room as a separate tilemap, and then arrange them in a larger world map like in the Metroid game. The only problem I am having is how to get around the possible error of mismatching doors... if the are not lined up the same on adjacent rooms (the door that they share) then there may be complications... I just don't know how to make the program handle this if it occurs... Also another difficulty I am having is how I can layout the world... would it be better to lay out the world in a "world editor" then edit each room in a "room editor", or should I just design each room, link them with doors, and just create a representative graphic for the world? But then... what if it is not exactly correct? any advice out there?

##### Share on other sites
Sijmen    231
First, about the doors not connecting, you should really just avoid that in the map design. It's a bit weird if you enter a high door and leave a low one. So, just try to allign the rooms.

For the editor, it would be best if you'd have some world-editing like mode, that displays the rooms as blocks, and their connections as lines or something like that. Then allow the user to click a block (or double click, whatever you want), and open a window to edit that single room.

You might get some happy map designers if you'd allow dragging rooms or biffere selections of rooms around, by the way.

Good luck!

##### Share on other sites
beaner    100
Thanks for the advice, Sijmen. That's the idea I had in mind, but then the question of the doors came in... I know that I can avoid the problem in the design, but I might not catch a door that is off by, say, one tile... how can I have the editor catch this for me? plus the world editor must distinguish the boundaries of the room (so a correct sized tile map is opened up when double-clicked), and allow for irregular shaped rooms... I will play with a bit when I get some spare time because I think I can come up with some more ideas. Thanks for the advice, and if you have any more please post!

##### Share on other sites
lucky_monkey    440
Quote:
 Original post by beanerI know that I can avoid the problem in the design, but I might not catch a door that is off by, say, one tile... how can I have the editor catch this for me?
When a connection is made between two rooms the map editor can check if the doors line up and warn if they don't. When creating a new room the map editor could display the positions of doors in adjacent rooms somehow (if the new room is created with pre-existing connections to other rooms).

##### Share on other sites
leiavoia    960
I agree that making doors align would best be left up to the designer and not the app. Anything else in unecessary and a lot of work. However, if you are looking for a double-check function, what you would do is this:

- Two rooms: A and B
- Find all doors in A that connect to B
- For each door in A, calculate the offset from door #1.
- check each offset from A and match to corresponding offsets in B. If any offsets do notch match between rooms, ERROR

   A         B-------   -------  2         2  |         |  |         |  |         |  ---1      ---1

As you can see in the above two room, the offset between door 1 and 2 in room A (-3x, +4y) matches the offset from 1 and 2 in room B (2 connects to 2 and 1 connects to 1). If the offset did not match, you would have an error.

If you were really anal, you could give each tile coord a location based on, not the room it's in, but the actual total world space, in other words, ROOM_COORD + TILE_COORD = TILE_LOCATION.

I'm also working on a Metroid-styled game. If you are interested you can drop me a line. I don't have world-loading made yet and probably won't have that until much later in the process. My world isn't strictly tile-based either but i will probably put that in for ease of use in world creation and editing. I have lots of other goodies in, though, including the main object processor, collision detection (not totaly finished, but certainly functional), physics, jumping, firing, health and stats, collectables, XML configurable input, XML configurable resource management, nice 2D OpenGL graphics, sound, music, and a bag full of nifty special effects including light, particles, etc. I haven't gotten to making the hundreds of chracter animations yet though, so i'm only using simple place-holder graphics until the core is done.

Screenshot 1
Screenshot 2

##### Share on other sites
kaysik    382
have you ever considered linking the doors instead of creating tilemaps that line up? It would be a bit more work but you could then be sure they'd work, and you could create some pretty crazy designs where the doors could change where they lead too or even have a door in the middle of a tilemap which leads to somewhere else!

You'd need to add a special section to your tilemaps called a door*. Each door has an ID and a "link too" field. So door 1 in level 1 might link to door 7 in level 8 for instance. Whenever your player enters a "door section" just load the map its linked to, then find the door and put the character there. It would be a little extra work, but it'd definatly be cool idea to try. The hardest part would be adding the door info to your map editor and file format but once done you could do anything with it. Make the player stand on a big fan and he gets blow up a level, stand on some quicksand and fall through the floor to the ceiling below, then when you get the flying ability you hit the ceiling and fly up through the quicksand. Have a teleporter than transports you from the world to the ship and back again, or a door that leads from the bottom of a cave into outer space - when you can link any door to any other door you get a world of possabilities.

*when i say "door" i really mean "area thats linked to some other area", "teleport region" or "portal". Enter area A and end up in area B - so many uses!

##### Share on other sites
leiavoia    960
^^^

I forgot to mention that. That is exactly how i plan to do it. It's actually less work and it's much more configurable as well. Like, let's say down the road you want to change the game, add to it, or even make a different world with the same engine. All you would really have to do it create some new rooms and/or re-link the doors to each other. If you export it to a config file, you could have non-programmers mod your game, simply by relinking rooms together!

All you would really do is export a "room" to a config file, have as many doors as you want and have each one with a "links_to" integer ID variable. That's it. In the game, when you actually walk through a door, the screen fades to black, it looks up the ID of the door on the other side, loads the corresponding room, and out you come. It wouldn't even matter if the doors "line up" or not because no one will notice.

##### Share on other sites
beaner    100

I planned on making doors special objects that linked to other doors, but I just wanted to be sure I could make an accurate representation of the world on a world map. It is true that by linking the doors, no one would really notice, but if the doors in 2 different rooms were offset by like half a screen, the world map may not be accurate. In super metroid, the squares on the world map represent one screen (16x16 tiles that are 16x16 pixels each)...

However, you all have given good advice and have some really good ideas... I should be able to pull something together. Thanks, and I will send you a message, leiavoia.

##### Share on other sites
Rhaal    754
Well, you said it's a tilemap. If all your tiles are the same size, it'd be easy. For example purposes, lets say your maps are 6x6 tiles.

o: open
w: wall/floor/ceiling
d: door tile

// Room 1       // Room 2  0 1 2 3 4 5     0 1 2 3 4 50 w w w w w w   0 w w w w w w1 w o o o o w   1 w o o o o w2 w o o o o w   2 w o o o o w3 w o o o o d   3 d o o o o w4 w o o o o w   4 w o o o o w5 w w w w w w   5 w w w w w w

You could run a check on room 1 to see where the door is [5,3]. With that info, you just need to make sure there's a door in the linked room at [x, 3]. To get x, use your tile offset from whatever side of the room you're on. In this case, it'd be 5 tiles offset from the right wall to the left.

So, if the door in the linked room is at the offset (go back 5 so x == 0, [0,3]). You could do pixel-precise offset checking, but you ARE using a tile map.

For ceiling/floor doors, you could do the same with the y offset.