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
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
y (maybe a third for
- 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.