Imagine the player is outdoors. He walks up to a building, and walks on top of a door. The door is a teleporting tile that teleports him to the inside of the building. It's teleporting, but there are no flashy energy effects or anything, you just switch the player from (area, x, y) to a new (area, x, y), and the screen instantly changes. That's what I mean by teleporting.
I understand todays PCs would have no problem working with such a large tile map, but atypically that would require a large amount of memory to hold the huge tile map if I would to have all areas exist within that huge tile map.
Nope, because here's a secret: Each area is a different tile map. You only need to load the area the the player is currently in.
- Player starts game.
- Load "peaceful_town_outdoors.map"
- Place character at tile (150, 75).
- Player walks around.
- Player walks on top of the tile that looks like a door.
- Unload the previous map.
- Load "peaceful_town_indoors.map"
- Place character at tile (30,30).
The exact same thing happens when going from a town into a forest, or from the forest to the grassy plains, and so on. Invisible teleporting tiles.
Here are some screenshots from a tutorial I wrote ages ago for a game that is no longer online (the tutorial also is no longer online).
In this particular game, we'd have walls that'd look like this:
(stairs up and stairs down)
And in the editor it'd look like this:
Wl = wall
Wp = warp
Stepping "on top of" the stairway would teleport you to a different map.
Same with ladders:
When entering these areas, I'd make sure to make the "landing location" of the warp that led into the area go one tile beyond where the exit is.
Imagine this being a hallway that connects two separate areas together:
The same thing applies for walking into tunnels:
(ignore the light blue 'Nm' markers, they aren't relevant to the current discussion. Also ignore the FG, BG, Grd markings =P)
This is just one way of doing it. In that specific game, every area had an ID instead of a name. So we had area 1, area 2, ..., area 756, etc... (over 1000 areas in total).
Every tile in a area had, in addition to other things, five integers similar to (but not exactly like) this:
enum TileType{None, Wall, Warp, NPC, Chest};
struct Tile
{
//The ID used to lookup what graphics to draw for this tile.
unsigned int imageID;
//What type of tile this is.
TileType type;
//The extra data given to the TileType.
//Depending on the TileType, these arguments are treated differently.
//For walls: these are ignored.
//For NPCs, 'argA' is the ID of the NPC's dialog script.
//For Warps, 'argA' is the ID of the area to warp to, 'argB' is the X tile to warp to, and 'argC' is the Y tile.
//For Chests, 'argA','argB', and 'argC' are IDs of items in the chest (for up to three items. Set an arg to 0 if there is no item there).
int argA, argB, argC;
};
I wasn't the programmer for that specific game, but when scripting or using the map editor, it gave a fairly good picture of how things worked under the hood.
This example is very simplistic, but it works. If you've already learned about unions, this might be a decent place to use them.