Ok, since the replies from my recent topic were such a bit help, I'm hoping I'd get the same here. I took some of your advice and decided to have my level data put into a binary file. I've run into some problems though. I have a struct and a class. The struct is where the level data is read into and the class has a declaration of the struct and some other functions to load the level and such.
struct Level_Data
{
int s_Level; // Current level
int s_Distance; // Distance until boss
char* s_Boss; // Boss directory
};
class CLevel
{
public:
int InitLevel(char *dir); // Initialize the level
Level_Data m_LevelData; // The level data
};
And so far I have the InitLevel() funciton like so:
int CLevel::InitLevel(char *dir)
{
char filename[255]; // The filename
char buffer[255]; // Buffer
FILE * fp; // The file
sprintf(filename, "%s/leveldata", dir); // Load the filename into a string
// Try to open the file
if((fp=fopen(filename, "r")) == NULL)
{
// If the file could not be opened, print an error message
printf("ERROR opening file %s\n\n", filename);
return 1;
}
// Get the first three lines of the file to set the current level, distance needed and the boss directory
fgets(buffer, 255, fp);
sscanf(buffer, "LEVEL: %d", &m_LevelData.s_Level);
sscanf(buffer, "DISTANCE: %d", &m_LevelData.s_Distance);
sscanf(buffer, "BOSS: %s", m_LevelData.s_Boss);
fclose(fp);
return 0;
}
And last but not least, I have my binary file (or what it's made of so far):
LEVEL: 1
DISTANCE: 10
BOSS: data/meteor
In my main loop, I have a function that prints out the data stored in s_Distance, s_Level, and s_Boss. My problem is that when s_Boss is printed to the screen (the data path extracted from the binary file) it only prints out (null)
VG-Force |
Ekim Gram Productions
[edited by - Ekim_Gram on March 23, 2004 7:58:48 PM]
[edited by - Ekim_Gram on March 23, 2004 7:59:32 PM]
[edited by - Ekim_Gram on March 23, 2004 8:27:01 PM]