• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Best way to store levels

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!).
 
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic