This topic is 4995 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

hey i was hoping to make the platformer map file look somthing like this..
Quote:
 map { width = 100 height = 100 tileset = fred.bmp } tile { x = 10 y = 2 picture_x = 5 picture_y = 3 }
Problem is im a bit confused how to read somthing like that. Im not sure if i would want to loop through the characters or the lines of the text file. I searched around a bit, but i could only find information for c++ not c. Could someone point me in the right direction? Thanks, kzar

Share on other sites
Probably your best bet is to make the format simpler. It sounds like with that format you'd need a tokeniser and all sorts of messing around to match up the curly brackets etc.

I'd go for the simplest thing possible. As a platformer is probably tile-mapped, then one character per tile and a text file which looks like

  G    =*******=******       =       =************             ***                  ****  S***********************

Or something - say for example, if a * is a platform and = a ladder or something, you could make S the player start point and G the goal.

Even if you have angled tiles, creative use could be made of the ascii-art favourites / and
If you need variable-sized maps, either just place the size at the top on two separate lines (which can be read with fgets() and atoi or sscanf or something like that), or store them somewhere else.

If your maps are too big to easily edit this way in a text editor, consider using a bitmap editor instead. Presumably your program has some facility to load bitmaps in some format - you can just read the colour indices out (if it's an indexed format) and use them for tile IDs.

Mark

Share on other sites
Your format looks nice for XML processing if you just change it a little. Anyway, it will be better if you use a binary format instead of a text format.

Luck!
Guimo

Share on other sites
Binary formats suck unless you have a convenient editor for them.

There are two obvious formats for tilemaps - text files (Editable in your friendly text editor, complete with cut / paste and undo)

Or bitmap graphics - Editable in your friendly bitmap editor, completely with cut / paste and undo.

If you use some weird custom binary format, you'll need to write either an editor or converter, which would be extra code.

And seeing as good programmers are inherently lazy :) ...

Mark

Share on other sites
bite the big one and make a level editor. its surprisingly easier then you think. you can copy and paste the majority of the code for it strait from your game...

Share on other sites
thanks guys those are some really clever sugestions!

edit: how does the format being xml help by the way? surely it would be just as hard to read?

Share on other sites
Use a XML parser... like TinyXML. Just open your file and start reading the data. Easy.

But binary format may be better (hey... a bitmap is binary too remember). You need an editor but as someone else said, if you have your game working, then you can tweak it a little and create a level editor.

Luck!
Guimo

Share on other sites
hmm well the thing is im starting the game with the level loading, i havnt programmed it at all yet! I think il have a try at the xml way, it sounds good.

Share on other sites
oh I dunno, heres some random puesdo-code

bool inTag, inVar
char *var, *tag, value

while(char character != end of file)

if( character = ' ' || '\n' )
continue
if( character = '{' )
inTag = true
else if( character = '}' )
inTag = false

if( character = '=' )
inVar = true

if( !inTag )
tag += character
if( inTag )
if( inVar )
var += character
else if( character = ';' )
inVar = false
tag.var = value
else if (!inVar)
value += character
end while

Dont take that seriously, but you could write a string parser which checks for your own syntex. The above one ignores spaces, end of line characters, expects ; at end of assignments etc... in theory at least :)

Share on other sites
hey that doesnt look tooo complicated actualy, i think il give it a shot. I know what to be doing roughly now ;).

1. 1
2. 2
Rutin
24
3. 3
JoeJ
19
4. 4
5. 5
gaxio
13

• 17
• 40
• 23
• 13
• 13
• Forum Statistics

• Total Topics
631729
• Total Posts
3001918
×