Tile Based RPG Resource Management and Loading

I’ve started work on a Tile Based RPG (Link To The Past kind of deal). The way my world is setup is that I have 3 or 4 levels, and within each I have a bunch of areas that are free roam. So, when the player moves off the screen it transitions to a new area, rather than having the screen scroll with the character.
I would like to ask about loading resources. As far as a tilemap goes, the layout of the tiles would be stored in a file, and loaded from that. That’s simple enough. What I’m unsure about though, is loading objects into the maps. Say collectible items, or objects the player interacts with. Are these items typically represented by tiles as well? I’m not sure how to handle this.

For example, say I have a Key class. Within the key class it has an ID of the door it unlocks. Say one level has some 20 doors to unlock. I could load these into the game the same way as tiles (via a file), but how do I decide which key is which and where it should go?

This question has gotten kind of confusing. Please ask for clarification if it is needed.

I would use some sort of XML system to define a specific key’s attributes. How are you currently loading maps? Using a text file or through a image? If you’re using a text file, just create a new number that corresponds to a tile with a key on it.

Example:
0 = void tile
1 = grass tile
2 = grass tile w/ key

00000
01210
00000

Your program will then loop through and find the 2, create a new grass tile (or whatever you need) and then create a new instance of a key and place it at that tile’s location. It’s pretty much the same for a map loaded through an image, you just use a different color and when the game finds that color in the map, it creates a new tile and key and adds the key to the tile. That’s at least how I would do it!

For the actual key attributes, I think you should think some more about how you could accomplish this. Hint, you need to give the key class a door object.

That’s how I’m loading the tilemaps, yes. That’s no issue. I think loading the actual objects through a file would work well, too. Let me refine my example to explain the issue a little better.

I have a key class. In my file, if there is a key on a tile, I’ll place a 1 on it.

Now, I go to parse the file, and I come across a 1. So, my parser creates a new key (via new Key():wink:
I come across another 1, and do new Key(); again.

How would I assign doors to these keys, considering my parser is creating the objects? Basically, how do I differentiate 2 different instances of the same class? I figure an ID, but how can my parser assign these ID’s? And in my opinion for the door, rather than giving the key a door object, the key and door just need to have the same “key code” (A number that has to match).

I kinda-sorta get what you’re saying. The way I’d do it, which is probably a bit too long, would be to have a text file that looks like this:

KeyID, DoorIDForDoorThatKeyOpens, WhereKeyIsOnMap
KeyID, DoorIDForDoorThatKeyOpens, WhereKeyIsOnMap
KeyID, DoorIDForDoorThatKeyOpens, WhereKeyIsOnMap
etc…

Just load and parse the text file for the information then do whatever you need to with that information. The WhereIsKeyOnMap decides where the key is on the map, DoorIDForDoorThatKeyOpens decides which door the key opens and the KeyID is for something that I forgot while typing this.

Hopefully this gives you some ideas for different approaches to solve your problem.

Hm. I guess that’d be the most appropriate choice. Is that fast? Should I just load all the assets at the start of the game?

I doubt you’d even notice any difference in loading time as long as your text file isn’t absurdly long (a few thousand lines). Load it whenever you want; if you’re putting the keys on the map right away then load the text file right away.