Jump to content
  • Advertisement

Archived

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

drdarkon

Level Editor

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am doing a top down puzzle game. I want to have a level editor. Now that I know how to load the levels, that helps a lot, but how do I save a level that is made in the level editor? My levels are going to be stored in numbers (an array)... I will define the numbers as stuff like LEVEL_FLOOR for easy refrence. How would I go about saving a level I have made (I think I asked that twice... anyway) - Thanks

Share this post


Link to post
Share on other sites
Advertisement
Basically, make a list of all the data that is needed to describe the level. Go through every array outputting every number (or whatever) into the file. Then output every variable into a file. Just make sure you read it in the same order that you write it.

[edited by - Mulligan on June 30, 2002 10:52:00 PM]

Share this post


Link to post
Share on other sites
Okay I understand. How would I go about writing all the info to a file? Sorry about all the questions, this is only my second game

- Thanks a bunch

Share this post


Link to post
Share on other sites
if you're using C++ you can use standard C calls.
I'd write the info out in text form first off since it seems you haven't had experienc with file IO before, that way you can open it with a text editor and see that it looks right.


  
FILE *fp = fopen("MAPFILE.TXT,"w"); // open for writing

// if the board width/height is variable, write it out first

fprintf(fp,"
BoardHeight: %d\n",BoardHeight);
fprintf(fp,"
BoardWidth: %d\n",BoardWidth);
// write each entry out (assuming each is an integer)

// separate each by a comma and have a new line at the end

// of every row

for (int i=0; i<BoardHeight; i++){
for(int j=0; j<BoardWidth; j++){
fprintf(fp,"
%d,",GameBoard[i][j]);
}
fprintf(fp,"
\n");
}
// write out the variables (do this for each one)

fprintf(fp,"
LEVEL FLOOR: %d\n",LEVEL_FLOOR);
fclose(fp); // close the file


then to read in a file you could do:

  
FILE *fp = fopen("MAPFILE.TXT","r"); // open for reading

// get the board width/height

int BoardWidth, BoardHeight;
fscanf(fp,"BoardHeight: %d\n",&BoardWidth);
fscanf(fp,"BoardWidth: %d\n",&BoardHeight);
// allocate space for the game board

int **GameBoard = new int[GameHeight][GameWidth];
for (int i=0;i<BoardHeight; i++){
for (int j=0; i<BoardWidth; j++){
fscanf(fp,"%d,",&GameBoard[i][j]);
}
fscanf(fp,"\n"); // skip the new line

}
// read in the variables

int LEVEL_FLOOR;
fscanf(fp,"LEVEL_FLOOR: %d\n",&LEVEL_FLOOR);
fclose(fp);

If I haven't messed up the above, it should do the trick.

Good Luck
Toby


Gobsmacked - by Toby Murray

[edited by - tobymurray on July 1, 2002 2:11:54 AM]

Share this post


Link to post
Share on other sites
Okay thank you. That last post was very helpful... I have a question though... what is that last part using LEVEL_FLOOR? What do you mean write out my variables.. could you explain the purpose of the last part of each of those please?

- Thanks again

Share this post


Link to post
Share on other sites
Also, how should I set up my map?

Like this?

1 0 1 3 5 1 2\n
1 2 4 1 2 1 1\n
1 1 1 1 1 1 1\n
etc..

or like this:
1,2,4,1,1,1\n
1,1,1,1,2,1\n
1,2,1,2,2,2\n

Sorry about all the questions, but thanks for the help

Share this post


Link to post
Share on other sites
Also... oh boy.. I am having problems getting this code to work... I am not exactly sure how this is all used and how it all plugs in... boy oh boy... I think I need a bit of an explanation here... sorry for the hassle...

- Thanks

Share this post


Link to post
Share on other sites
Oh yeah I forgot to add: I am referring to the loading file routine right now... I will worry about saving at a later time. I keep getting debug type errors with fscanf telling me that stream!=NULL... what am I doing wrong? I changed the code a little bit... bah...

- Thanks

Share this post


Link to post
Share on other sites
Sorry about all the posts... I really am... I jut realised.. the LEVEL_FLOOR I was refering to should have been like this: I meant that each of those numbers in the map array would have a corresponding define to make it easier for me to program with... so LEVEL_FLOOR = 1, LEVEL_FIRE = 2, LEVEL_PIT =3, etc...

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!