Here's a way it can be done (which could pretty easily be adjusted to suit your own format): boolean read_level_file(const char* filename) { int rows = 0, cols = 0; FILE *fp = NULL;
Pacman is my main character in my game. I store all of his information in this struct: struct sprite { unsigned int score; unsigned int level;
unsigned int x; unsigned int y;
unsigned int direction;
char name[50]; }pacman;
So Pacman is a sprite structure, and direction is just an integer in the sprite struct that tells which way he is facing. Whenever I load a level, I read what way he should be facing. fscanf(fp, "%d", (int*)current_level.tile[rows][cols].type);
fscanf() is a function that takes a printf() like format string and read what you wanted it from a file. "current_level.tile[rows][cols].type" refers to my level structure. I cast it to an int* so I won''t get a stupid warning... So what I do is that the line will read an integer from a file and store it in current_level.tile[rows][cols].type.
/. Muzzafarath
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Yes, that helps to clear things up. That code makes perfect sense, however I tried it and it's not able to open the file. I checked the filename and it is correct. I even tried entering the exact path to the filename. I tried opening it with a "r" for reading and tried "r+" also. I'm not too sure what I'm doing wrong this time. As soon as I call the function to load the file it just exits the program. Sorry to keep bother you guys.
Edited by - Nazrix on 4/17/00 5:46:01 PM
Need help? Well, go FAQ yourself. "Just don't look at the hole." -- Unspoken_Magi
Ok, I see that none of these guys answered the question right. First of all, this is just a 2 dimensionnal array. It can be accessed as world[1][1]="1";// change the first character or world[1]="111111111111111111111111111111";// Change the first line. This is the way to access these types of variable....
Cyberdrek Headhunter Soft DLC Multimedia Two Guys Soft