wood burning stoves*
The moose likes Game Development and the fly likes Best way to store levels Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Game Development
Bookmark "Best way to store levels" Watch "Best way to store levels" New topic
Author

Best way to store levels

Nikhil Marathe
Greenhorn

Joined: Oct 15, 2005
Posts: 6
What is the best way to create easily modifiable levels. I don't want it to be in code, they should be sperate files. Is XML or text better. And if the levels are in order then suppose i have a variable called nextLevel which represents the next level then should it just have the name of the level file or a nice, pre made level object

Thanks,
Nikhil
James Swan
Ranch Hand

Joined: Jun 26, 2001
Posts: 403
Depends on your type of game.

Eg. if your game was a tile-based platformer, a simple text file would probably be a good choice, using different characters to specify different game objects, '*' could be monster A, '$' could be reward X, etc.

As for choosing next level, one approach might be to just name the level files so they have a natural order ('level001.txt', 'level002.txt',...). That way you can just iterate over the directory containing your level files.
Jean-Sebastien Abella
Ranch Hand

Joined: Jul 29, 2005
Posts: 60
hi,
from previous experience I can assure you that an XML file is an excellent way of "storing" levels. The way I did it was to have an LevelManager class that is responsible of loading/saving(for the level editor) and provide the next level. So basicaly the class looks like this:

LevelManager
+ init()
+ Level nextLevel()
- List levels

So this class is instantiated by your game object. When the game calls init, the class LevelManager will do some preliminary stuff. For example it can read an xml file containing the list of levels files and the order, the levels size, ... . Then the game will start and will need a level so the Game calls levelManager.nextLevel(). So the responsability of nextLevel() is to fetch the right file and construct the level on the fly( you probably want to cache it if you go back and forth(such as Mario 1 where loop forever) and when the level object is done it returns it. Then in your game you have the level Object that you can do anything with(such as rendering it! doh!).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Best way to store levels