Level data structure

Apprentice
Posts: 9
Joined: 2008.12
Post: #1
Hi,
Im trying to work out the best way to handle level data for a 2d scroller, theres a world class with several (10) levels:

struct Level {
int height;
int width;
int tiles[];
texture *leveltexture;
}

Level *world[10];


Two questions:
-Does this look like a reasonable way to manage the data
-How best to load the data structures, i could put the data in a file and loop through each level but since i dont need the flexibility of data files could i just put the level data in headers and have the struct set up that way?

Thanks!
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
tfifriday Wrote:-Does this look like a reasonable way to manage the data
Looks reasonable, as long as having a hard limit of 10 levels in your world will never be a problem.

tfifriday Wrote:-How best to load the data structures, i could put the data in a file and loop through each level but since i dont need the flexibility of data files could i just put the level data in headers and have the struct set up that way?
Both are valid approaches, though there are some caveats with each. For example, if your data is compiled into your program, that means that every time you want to change one of your levels will require a recompile. This can be inconvenient in some cases. However, if you put it in a data file, it's more easily editable by the end user, which may allow cheating if you don't put in measures to prevent it (if cheating is even a real problem in your game). Not that compiled-in data can't be edited, but it's a lot easier if it's isolated in a data file.

There are some finer points of this depending on the sort of game you're making, but I wouldn't discard one solution or the other up front. It's a matter of picking the one that best suits your situation.
Quote this message in a reply
Apprentice
Posts: 9
Joined: 2008.12
Post: #3
Thanks,
I dont need to update the level data, its going to be fixed so i like the idea of including it in the source.

The question is, i dont want to put pages of map data in the world constructor but cant initialize structures in a header. Is there a neat way to set up the data in a seperate file and have it availble to the world class as an include or do i need to have all the data in the world class file?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #4
The way I tend to do things like this is to have a "loadDefaultData" function that lives in an implementation file somewhere (which doesn't necessarily have to be in the same file as where you're using it) that fills out data structures at runtime with the appropriate static information. You'd call this function relatively early on in your execution. For anything nontrivial, I find it's more hassle than it's worth trying to get variables' default values at compile time to match up to what I want, but maybe you'll have better luck than I did...
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Basic structure of an iOS game with OpenGL whitey 0 3,769 Oct 4, 2011 09:40 PM
Last Post: whitey
  saving/reading level data using plists aerospaceman 6 4,570 Nov 29, 2010 02:44 PM
Last Post: aerospaceman