示例#1
0
文件: World.cpp 项目: TheZoq2/Below
void World::loadFile(std::string file)
{
	char wallChar = '#';
	char floorChar = 'f';

	if(agk::GetFileExists(file.data()))
	{
		//Opening the file
		int fileID = agk::OpenToRead(file.data());

		int cX = 0; //The current x row
		while(agk::FileEOF(fileID) == 0)
		{
			Part noPart;
			noPart.setup();
			//Fixing vectors
			std::vector<Part>* tempVec = new std::vector<Part>;
			floor->push_back(tempVec);
			tempVec = new std::vector<Part>;
			walls->push_back(tempVec);

			char* linePtr = agk::ReadLine(fileID);
			std::string line = linePtr;

			for(unsigned int z = 0; z < line.size(); z++)
			{
				if(line.at(z) == wallChar)
				{
					//Selecting a base
					int baseIndex = rand() % wallBase->size();
					
					PartBase* base = &wallBase->at(baseIndex);

					Part part;
					part.create(base, cX, 1, z);

					walls->at(cX)->push_back(part);
				}
				else
				{
					walls->at(cX)->push_back(noPart);
				}

				if(line.at(z) == floorChar)
				{
					//Selecting a base
					int baseIndex = rand() % floorBase->size();
					
					PartBase* base = &floorBase->at(baseIndex);

					Part part;
					part.create(base, cX, -0.5, z);

					floor->at(cX)->push_back(part);
				}
				else
				{
					floor->at(cX)->push_back(noPart);
				}
			}

			delete[] linePtr;

			cX++;
		}
	}
}