# storing map data as file in 3d roguelike games

I'm currently designing 3d roguelike game. I need to come up with a map storing system but I'm quite new to game programming so I don't really know how to design. The map will be relatively small, it's not open world. I think it would be just like 3d version of The Binding of Isaac with first-person perspective.

I want to store map data as a file(e.g txt) but I don't know how to order them and what is necessary to store.

Answers with some examples would be very appreciated.

• What data does your map use in memory? We need to know that information before we can tell you how to store that in a file. – DMGregory Sep 27 '18 at 3:13
• You can store the file however you want, it is entirely up to you. – user253751 Sep 27 '18 at 3:27

Think of it this way. If you are reading the file that has the map, what data would you need to accurately re-create a map?

Is your map tile based? Then for each tile you have to define things like:

• What does it look like? (assuming you are using 10 different meshes as tiles, this could be a number from 0-9 that describes what tile it is using)
• What's its location in the world? This could be either x and y, but you can also add a z if your maps have height as well
• Does this tile have an enemy on top? Which enemy is it? (Similar to the meshes above, you can use IDs for enemies as well) You can also save information if the enemy is still alive (in case you want to save/load an already explored map).
• Is there any treasure on this tile? Etc etc

I think this gives you an idea of how to do it. You can follow almost the same procedure if your maps are not tiled, but it might be more cumbersome.

So based on all the information, organise them inside your file for example:

• An integer for mesh ID
• 2 floats for x and y (maybe a third for z)
• An integer for enemy ID (0 for no enemy)
• An integer for treasure ID (0 for no treasure)

When saving a map, iterate through all tiles, and put their information in a file like this, when loading a map, read the file the same way. This is the basic idea, hopefully you can use this information for your own game.