Jump to content
  • Advertisement
Sign in to follow this  
Jesse Dager

Level Loading Lark

This topic is 2052 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 beginning to create a simple level loader for my game engine. It has a simple syntax, so I figured it would be pretty easy to create... How wrong I was. 

 

Below is the code for decoding my level files:

void JTechScript::JLoadLevel(const char *filename)
{
	objects = 0;
	//initialize variables and get load file
	fileName = filename;
	std::ifstream levelFile(fileName);
	char letter;
	letter = levelFile.get();
	//begin insane nested loop stuffz
	//go until the end of file
	while(letter != END_FILE)
	{
		//check for new object character "#"
		if(letter == NEW_OBJECT)
		{
			//initialize more stuffz
			char tempObjectType[32];
			int x = 0;
			objects++;
			//read until end of line and make that the name of the object
			while(letter != END_LINE)
			{
				std::cout << letter;
				x++;
				tempObjectType[x] = letter;
				letter = levelFile.get();
			}
			std::string objectType(tempObjectType);


			//-------------------------------------------------------------------------
			// \/ \/ \/ \/ \/ custom object types here \/ \/ \/ \/ \/

			if(objectType == "CAMERA")
			{
				objParameter[objects][1] = 1;
			}
			else if(objectType == "WORLD")
			{
				objParameter[objects][1] = 2;
			}
			else if(objectType == "SPHERE")
			{
				objParameter[objects][1] = 3;
			}

			//END CUSTOM PARAMETERS
			//--------------------------------------------------------------------------


			//more initialization 
			int tempParameterNum;
			char buffer[32];
			int value = 2;
			//read until the end of the object
			while(letter != END_OBJECT)
			{
				tempParameterNum = 0;
				//read each line and make it a number
				if(letter != END_LINE)
				{
					std::cout << letter;
					buffer[tempParameterNum] = letter;
					tempParameterNum++;
				}else{

				//set the number as an object parameter
				value++;
				objParameter[objects][value] = atoi(buffer);
				//clear the buffer
				for(int i = 32;i < 32; ++i)
				{
					buffer = 0;
				}
				}
				letter = levelFile.get();
			}
		}
		letter = levelFile.get();
	}
	//if you can figure this out, you deserve a medal. So... (1) <-- there... there is your medal.
	//................................................................SHUDDUP! I SUCK AT ASCII ART!
}

 

 

This is the file it is decoding

 

#CAMERA;
0;
100;
0;
|

#WORLD;
-100;
-10;
-100;
|
*

 

 

It seems to work fine, but when I try to retrieve the values for objParameter[1][1], it returns -842150451.. It returns the same number for objParameter[2][1] as well.

 

 

Please help... I have been working FOREVER on this.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!