Sign in to follow this  
Aspaul

How to save levels?

Recommended Posts

I am making a game wsing opengl and c++ and I understand that each level is made of componants such as the terrain, objects, enemys. Does anybody know the best way to store level information into loadable files or maybe the location of some articles on this subject. For example - take a simple game that the level consists of a 100x100 terrain map, coordinates for the player startpoint and coordinates for 10 enemys. What options are available Can I load all information into a class that contains all the level information then write the class to a file. Or should I just have a text file with a standard format seperated my specific markers and read the info in line by line. Please help or point me in a good direction. Thanks

Share this post


Link to post
Share on other sites
Hi,its simple to save and loade levels ...
fist , assign a number for the levels to track it .
2nd , if you want to save the level, save the camera pos , the number of the level, the player's health state , ...etc to a file ok ?
3rd , to load the file , read the saved infolike " the camera pos (X,Y,Z) , level's number ..etc " )

Ahmed Saleh

Share this post


Link to post
Share on other sites
I would go one of two routes myself, depending on the type (and amount) of data to be saved:

1) I'd use a binary file, not a text file. However, instead of just writing stuff straight out to disk from a class or struct, I would write each item out individually. This can save a lot of headache since some people run into problems with compiler packing options, big-endian/little-endian, etcetera, when they write out an entire struct, byte for byte. Also, you might end up needing some special organization, if your data normally contains pointers. Under normal circumstances, you obviously can't just write out the pointers to memory, and then expect to read them back in and have everything work.

2) I'd use something such as XML. It's better than a hacked together text file format, because it is more robust and flexible. However, if you are going to have a lot of data, much of it numerical, this might not be as good. It takes up a ton more space on the hard drive, and takes a ton more time to parse. A simple text file isn't as bad in terms of speed and size, but even it is a lot worse than a binary file.

So my conclusion: Use a binary file, but write each item out one at a time. Make sure to have a very well defined format.

For example, the beginning of the file contains 8 bytes, which is 2 4-byte unsigned values indicating the width and height of your terrain. You read these in, and then you know exactly how many values you need to read in to get all of the terrain data. Then, you would have another 4 bytes representing the number of enemies. After reading that, you can read the 12-byte x,y,z coordinates of each enemy. Then, you have 12 more bytes which are always the player startpoint coordinates.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this