Level, Asset, Save File storage

Can anyone give me pointers on how to store levels and assets without hard-coding them? Also how to store save user saves.

What kind of assets ?

you have sprites, soundfiles, music, tilesheets, fonts, whatever… these are all external files of course.

map files aswell. Usually map files only contain “configuration information” if you will, like a XML file. Kinda like: map size, which tileset and then a table of which tile is where… maybe layers and all sorts of stuff
you may write you own map system and editor or use one of the free ones - then you need to have an interpreter for these files… “Tiled” is a free one which many libs seem to support.
I always write my own, much more flexible

Save user saves. Well Serialize. Use Java Serialization, called the “Serializable” Interface and then you use objectoutput and input stream to write and read.
I like to use Kryo because it has this option to ignore missing fields and stuff, which helps savegame compatibility. But it has its own complications aswell.
You could write your own config and save it, using xml, json or even your own text file format

You might want to be more specific, there are so many ways to store and load levels, assets, saves, etc…

So, for assests, i mean like tools, ships, weapons with their sprites and all the metadata associated with the assets. So for a tool, that data would include its functions, its cost, its power, etc… I would like to have the sprites and metadata stored in one file. For the level files, I will have a bunch of pre-defined levels that will have cutscenes and enemies, obstacles. Drops and loot will be both randomly generated, but in pre-defined spots and also specified explicitly. Save files should allow users to reset everything back to the exact way it was when they saved.

For most of those things, except for the save file, you could just use a database such as Derby or something like that.

As anon951759 said there are a lot of different ways to store assets for a game so it really just comes down to your personal preference. For me I usually just store maps/character data/etc in a plain text file and read it in at some point in the game. I personally just don’t feel like messing with a database, or an XML parser, or a JSON parser, or what have you. Of course that means I end up writing my own little parser but that doesn’t take much effort at all really and it can just be reused from project to project.

Ok. Sounds like this is more personal preference than I thought. Well, thanks for the advice.

i would recommend to use the Jackson JSON parser, it will be a lot easier and less complicated then some handcrafted thing.

just create little data classes like:

class LevelData
{
String titel;
int enemyCount, maxTime;
}

which can be loaded & saved like this:


ObjectMapper mapper = new ObjectMapper(); // can reuse, share globally
//to read
LevelData level1 = mapper.readValue(new File("data/levels/level1.json"), LevelData.class);
//to write

mapper.writeValue(new File("changed-level1.json"), level1);

here is a more complete tutorial: http://wiki.fasterxml.com/JacksonInFiveMinutes

Okay. Thank you for the pointer. I will look into that.