예제 #1
0
// read keywords from files, initialize structure Keys with keyword and 0
int InitKeys(std::string fileName, const std::string splitString, KeysList& keysList) {

	std::fstream fsRead;
	fsRead.open(fileName.c_str(), std::fstream::in);
	if (!fsRead) {
		return 10;
	}
	
	keysList.clear();

	// read all contents of file once
	std::stringstream ssBuffer;
	ssBuffer << fsRead.rdbuf();
	std::string fileContent(ssBuffer.str());

	fsRead.close();

	std::vector<std::string> vFunctions;
	vFunctions.clear();
	boost::algorithm::split(vFunctions, fileContent, boost::algorithm::is_any_of(splitString.c_str()));

	std::vector<std::string>::iterator it;
	for (it = vFunctions.begin(); it != vFunctions.end(); ++it) {
		keysList.push_back(MakeKeys(fileName, *it));
	}

	return 0;
}
예제 #2
0
void Game::StartLevel()
{
   cout << endl << "Start level " << level << ":" << endl;
   
   // Set level size
   int levelWidth = 2000 + 2*Surface::SURFACE_SIZE*level;
   MakeMultipleOf(levelWidth, Surface::SURFACE_SIZE, ObjectGrid::OBJ_GRID_SIZE);

   int levelHeight = 1500 + 2*Surface::SURFACE_SIZE*level;
   
   viewport.SetLevelWidth(levelWidth);
   viewport.SetLevelHeight(levelHeight);
   flGravity = GRAVITY;

   cout << "  Dimensions: " << levelWidth << "x" << levelHeight << endl;

   // Create the object grid
   int grid_w = viewport.GetLevelWidth() / ObjectGrid::OBJ_GRID_SIZE;
   int grid_h = (viewport.GetLevelHeight() - ObjectGrid::OBJ_GRID_TOP
                 - MAX_SURFACE_HEIGHT - 100) / ObjectGrid::OBJ_GRID_SIZE;
   objgrid.Reset(grid_w, grid_h);

   // Create background stars
   nStarCount = (viewport.GetLevelWidth() * viewport.GetLevelHeight()) / 10000;
   if (nStarCount > MAX_GAME_STARS)
      nStarCount = MAX_GAME_STARS;
   for (int i = 0; i < nStarCount; i++) {
      stars[i].xpos = (int)(rand()%(viewport.GetLevelWidth()/20))*20;
      stars[i].ypos = (int)(rand()%(viewport.GetLevelHeight()/20))*20;
      stars[i].scale = (double)rand()/(double)RAND_MAX/8.0;
   }
   
   MakeLandingPads();

   // Generate the surface
   int surftex = rand() % Surface::NUM_SURF_TEX;
   surface.Generate(surftex, pads);

   MakeKeys();
   MakeAsteroids(surftex);
   MakeMissiles();
   MakeGateways();
   
   // Create mines (MUST BE CREATED LAST)
   MakeMines();
   
   // Set ship starting position
   ship.Reset();

   leveltext_timeout = LEVEL_TEXT_TIMEOUT;

   fuelmeter.Refuel(FUEL_BASE + FUEL_PER_LEVEL*level);

   // Start the game
   levelcomp_timeout = 0;
   state = gsFadeIn;
   fade.BeginFadeIn();
   life_alpha = LIFE_ALPHA_BASE + 1.0f;
}