Storing levels

Hi! I’m looking to make what’s shaping up to be a rather complex Rogue-like game.

I was looking to see what the best way to store levels was. I don’t feel like a txt file is the right way to go.

How do you fine folk store your levels for use in your games? (In case I’m missing something, I’m planning on using lwjgl.)

EDIT: For clarification, I just mean the best way to create and save a level to be read by the game while it’s being played.

Honestly I just use .txt files, unless you’re planning on actually releasing your game to the general public, I see no reason to do anything more complex. If you are going to release it, and are worried about modifying of the files, use a byte format maybe?

Haha well the option of releasing this game would be nice, although it probably won’t happen.

How is it done in games like VVVVVV or Super Meat Boy? That is one thing that’s always plagued my thoughts.

Honestly, I have no idea. I have never actually played either game :confused: I imagine they have their own file format though. I haven’t dealt a lot with file systems besides .txt files, but I’d recommend googling about file formats that are compatible with Java!

There are 3 options, and really, there are only 3 options that cover how everyone deals with file storage.

1) Hard code it

Store all your level design and objects hardcoded within the game. It completely alienates a lot of users from modding your game and makes it a little more difficult to do a quick fix in your levels. But, hey… the people will have to crack your entire code base in order to crack the game.

Java has a special serialization method that allows you to save states of its classes. It is a compromise between this option and option 2.

2) Put the data in a text file

This method takes your game data and puts it into a text file. Keep in mind, the extension does not have to be .txt. You can name the extension whatever you want. Also, you do not have to store the data as UTF-8 characters. You can store the data as a mixture of bytes, chars, and longs. As long as you are able to read the data back into the game you are fine.

This covers a lot of ways to store data, and is by far the one used by most indie and development companies working on large games. It includes most scripting languages like Lua, JSON, and XML. It also includes just writing your data into a basic text files under .txt and picture files like jpeg and png. You can also use this method to store data into binary.

The most important aspect is that you are able to read the data in and out of any format you put in the text file.

3) Store it online

This is really an extension of Option 2. But there is a few tools like MySQL and data servers where you can store all your data online and have the clients read off the server data. Of course, your clients will be out of luck if your system goes down, but MMORPG’s and other online gaming outlets all use this method of storing data.

Conclusion

Best way to handle it is possibly Option 2. It takes a little bit longer to write code that’ll be able to allow for custom objects and level design in the game. In the end though, it makes it a lot easier to expand your game to make more levels and objects.

I’ve just always used txts when I didn’t hard code my levels (now that i read this, perhaps I shouldn’t be giving advice ^^)
Does it just not feel professional to use a text file? Or are you worried about security, and the user editing the level?

I store my map as an image where each pixel corresponds to a tile. When I load the map I just load the pixel values into a 2D array and then render the map depending on the pixel values.

Thank you, thank you, thank you. this explanation just saved me so many questions (i had been told that serialization was the best way and the only option if i plan to allow players to play multi-player if they want, but this explanation contradicts that, and seems to actually explain it a bit more then others did.)

Thank you, thank you, thank you. this explanation just saved me so many questions (i had been told that serialization was the best way and the only option if i plan to allow players to play multi-player if they want, but this explanation contradicts that, and seems to actually explain it a bit more then others did.)

“Text file” is very misleading. All a “Text file” is a File (and all a File is a collection of bytes) which bytes are ordered in a way (codec/protocol/charset) that is familiar with most text editing programs.

An mp3 music file is a text file if you open it with a text editor. But the bytes are ordered in a way that text files can’t make sense of so you get a bunch of gibberish text.

The only reason you get a music player or a text editor opened up when you double-click/open a music or text file is because the suffic is either .mp3 or .txt - this suffix is only there to tell your Operating System which program (music player or text editor) it should try and open the file with (It essentially has nothing to do with the contents of the file).

“Text file” is very misleading. All a “Text file” is a File (and all a File is a collection of bytes) which bytes are ordered in a way (codec/protocol/charset) that is familiar with most text editing programs.

An mp3 music file is a text file if you open it with a text editor. But the bytes are ordered in a way that text files can’t make sense of so you get a bunch of gibberish text.

The only reason you get a music player or a text editor opened up when you double-click/open a music or text file is because the suffic is either .mp3 or .txt - this suffix is only there to tell your Operating System which program (music player or text editor) it should try and open the file with (It essentially has nothing to do with the contents of the file).

Yes - technically all files are “text” files. Anything can be opened with Notepad. Why do you think this is? Because higher-level interpretations can always be translated down to “text”.

Yes - technically all files are “text” files. Anything can be opened with Notepad. Why do you think this is? Because higher-level interpretations can always be translated down to “text”.

This. I do it exactly the same way in my game :slight_smile: I find that doing it this way is easier because you’re already seeing your map layout and it’s easy to change things just by modifying a few pixels.

This. I do it exactly the same way in my game :slight_smile: I find that doing it this way is easier because you’re already seeing your map layout and it’s easy to change things just by modifying a few pixels.

Technically all files are binary files. :point:

Text as in characters :wink:

You could gzip your objects.
It’s a built-in feature.

Technically all files are binary files. :point:

Text as in characters :wink: