#### Archived

This topic is now archived and is closed to further replies.

# Level files

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

## Recommended Posts

I am designing a space game as most of you know. I am nearly finished with the core of the game. What I am working on now is level files. This is the syntax I have so far for some of the easier functions:
  LEV: 1 -1 -1 ENEM: 0 10 11 -1s mean no data, n/a so this means, start level 1 filling. then, it will load up the array 0 enemy, and his x,y are 10,11 here is the code that does this (actually this is a test program, so its not in my game yet) : while(!feof(fp)) { fscanf(fp,"%s %d %d %d",arg1,&arg2, &arg3, &arg4); if(strcmp(arg1, "LEV:")==0) { } if(strcmp(arg1,"ENEM:")==0) { lev1.enemx[arg2]=arg3; lev1.enemy[arg2]=arg4; lev1.levnum=arg2; } } 
this is pretty simple. but, there are a few things I'm not sure of what to do. #1) Loading filenames, would I want to make a -1 kinda thing at the end of every line that has nothing to do with filenames? #2) I'm going to add in something called zapping. this isn't complex. It just says, after lets say, 10 kills, 2 more enemies "zap in." the syntax I was thinking for this would be:
  KILLS: 5 -1 -1 ZAP: index x y 
of course, the index, x, and y would be filled with real data. But what would my struct look like? how would I set up the set up the struct to do this? *edit*Spelling on source Edited by - Muzlack on February 19, 2002 5:49:08 PM Edited by - Muzlack on February 19, 2002 5:50:10 PM

##### Share on other sites
Does anyone know an open source space game including the level files in non-binary?

##### Share on other sites
Hmm.. Since I''m not getting any feedback here, I''m gonna guess that its because I''m not clear enough. Ok, All I want in my level file is the levels. They will all be organized like this:
LEV 1
...
...
...
END LEV
LEV 2
...
...
...
END LEV
In these levels, I would say which enemies start on the screen, and their type. For instance:
LEV 1
ENEM ALIEN1, 300(x),300(y)
END LEV
and that would be a really simple level. Now, after that, I want to add something called "zapping" after a certain amount of kills had been achieved. Kind of like a hyperspace thing in most games & movies, but I wanna call it zapping in my game. So, I was thinking the level file would look like this now:
LEV 1
ENEM ALIEN1, 300,300
ENEM ALIEN1, 200, 400
KILLS: 2
ZAP ALIEN2, 300,200
END LEV

So this would result in 2 enemies of alien1 type on the screen at the start. then, after you kill them both, an enemy of alien2 type "zaps" in. Now, here''s the question: How would I design my structs to support this kind of if statement with the kills? I was thinking I could have a condtion integer array with a max of 10 "zaps" per level. Anyways, I just would like some input on how other games do this.
Thanks!

##### Share on other sites
I would write a line by line text parser. Try ''google'' look up ''C Text Files'' and wade through. I used a five char tage at the start of each line followed by any data.

ie.

Level 1
Block 2, 3, 4
Block 2, 5, 4
Shape 4, 5, 6

etc

I looked for the tag then read in the data into the appropriate structs/arrays.
I also loaded the whole file into a string (buffer) and separated lines by looking for a carrage return followed by a newline marker.
Esc(13) and Esc(10) i think.

,Jay

• ### Forum Statistics

• Total Topics
628703
• Total Posts
2984301

• 23
• 10
• 9
• 13
• 13