Page 1 of 1
Loading level
Posted: Fri Jun 18, 2010 9:03 am
by adikid89
I was wondering how to go about doing that. Here is what I came up until now. I was thinking of making about 3 .txt files like: "level.txt", "units.txt", "titles.txt", "objects.txt". In level.txt I would have something like this:
0 0 0 0 0
0 0 0 0 0
1 0 0 0 1 // 1 - being a unit
2 2 2 2 2 // 2 - being a title
Then in titles.txt I was thinking of having: (more details about the type of title)
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
4 4 4 4 4 // 4 - being the 4th title
just a random title example could have been 1,2,3...
And in units.txt: (more details about the type of unit)
0 0 0 0 0
0 0 0 0 0
1 0 0 0 2 // 1 - being unit no. 1, 2 - being unit no. 2
0 0 0 0 0
But this just doesn't seem right... And I was looking for some alternative(better) formats for levels.
Re: Loading level
Posted: Fri Jun 18, 2010 11:07 am
by dandymcgee
Don't bother splitting everything into 3 different files, there are two perfectly functional ways (that I can think of off the top of my head) to toss it all into one.
The most obvious way is to throw newlines between each set of info.
Code: Select all
0 0 0 0 0
0 0 0 0 0
1 0 0 0 1 // 1 - being a unit
2 2 2 2 2 // 2 - being a title
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
4 4 4 4 4 // 4 - being the 4th title :shock: just a random title example could have been 1,2,3...
0 0 0 0 0
0 0 0 0 0
1 0 0 0 2 // 1 - being unit no. 1, 2 - being unit no. 2
0 0 0 0 0
The second would be to just use more numbers
Code: Select all
00 00 00 00 00
00 00 00 00 00
11 00 00 00 12
24 24 24 24 24
The first number tells you unit or title, the second goes more specific.
If you need more than 10 of each either use 10-29 for units and 30-49 for titles, or go to three digit numbers (allows up to 100 specifications).
Post back with any questions.
Re: Loading level
Posted: Fri Jun 18, 2010 11:20 am
by adikid89
Thanks that's a pretty good idea! What if I want to make a "custom" collision box? How would that look in the "level.txt" ? By that I mean making a 32x32 sprite or something, and making it's collision box 30x30 or something like that. Or would I have to make a brand new type for that? I'll give more power of thought for that later on though. I'll just go on with the game until then. Thanks!
Edit: I would still love to hear about how people handle level loading, maybe I would get some good ideas
Re: Loading level
Posted: Fri Jun 18, 2010 12:19 pm
by dandymcgee
adikid89 wrote:Thanks that's a pretty good idea! What if I want to make a "custom" collision box? How would that look in the "level.txt" ? By that I mean making a 32x32 sprite or something, and making it's collision box 30x30 or something like that. Or would I have to make a brand new type for that? I'll give more power of thought for that later on though. I'll just go on with the game until then. Thanks!
Edit: I would still love to hear about how people handle level loading, maybe I would get some good ideas
Yeah, I never really came up with a concrete system for loading object data. I had started putting each type of object's data into a file with an id, then having a section in the map file for which objects would be loaded where. You could store the bounding boxes in the object data file. I found it difficult to find any information anywhere on how other people had done this, so this method is just something I created on a whim.
The farther you get into game development, the less information you'll be able to find about what you're trying to do, and the more you really just have to invent your own system and better it as needed.
Re: Loading level
Posted: Fri Jun 18, 2010 1:18 pm
by ismetteren
adikid89 wrote:Thanks that's a pretty good idea! What if I want to make a "custom" collision box? How would that look in the "level.txt" ? By that I mean making a 32x32 sprite or something, and making it's collision box 30x30 or something like that. Or would I have to make a brand new type for that? I'll give more power of thought for that later on though. I'll just go on with the game until then. Thanks!
Edit: I would still love to hear about how people handle level loading, maybe I would get some good ideas
Then
I would keep the level data in level.txt and make another file units.xml in units.xml i would do something like this:
Code: Select all
<units>
<unit type="2">
<position>23,402</position>
<sprite>sprites/sprite.png</sprite>
<bbox>30,30</bbox>
<otherUnitInfo>info</otherUnitInfo>
[and so on...]
</unit>
[next unit here]
</units>
im no XML wizard and im not completely sure what should be attributes and what should be tags, but something along those lines. You could also use another format like YAML or just text files.
Re: Loading level
Posted: Fri Jun 18, 2010 3:46 pm
by adikid89
Thanks! I'll look into xml parsing, because I don't know a thing about it...