本文整理汇总了C++中Switch::addObject方法的典型用法代码示例。如果您正苦于以下问题:C++ Switch::addObject方法的具体用法?C++ Switch::addObject怎么用?C++ Switch::addObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Switch
的用法示例。
在下文中一共展示了Switch::addObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: loadLevel
/*
* File format:
* Level Name
* playerx playery
* exitx exity
* maxwells
* gravitywellfactor
* earthgravityfactor
* numwalls
* for numwalls:
* p1x p1y p2x p2y
* numswitches
* sx sy add numaffectedwalls
* for numaffectedwalls:
* p1x p1y p2x p2y
*/
ActiveGame* loadLevel(const char* filename) {
ActiveGame* level = new ActiveGame(filename);
Simulator* sim = new Simulator();
float h = GameEngine::getSingleton()->windowHeight;
float w = GameEngine::getSingleton()->windowWidth;
level->Init();
level->setLevelSimulator(sim);
ifstream file (filename);
if (file.is_open())
{
string line;
getline(file, line); // level name
float playerX;
float playerY;
float exitX;
float exitY;
int maxWells;
float wellFactor;
float earthFactor;
file >> playerX;
file >> playerY;
file >> exitX;
file >> exitY;
file >> maxWells;
file >> wellFactor;
file >> earthFactor;
GravityWell::setFactor(wellFactor);
Player* p = new Player(playerX, playerY, w, h, earthFactor); // strip newline?
Exit* exit = new Exit(exitX, exitY);
level->addStatic(exit);
level->addDynamic(p);
level->setPlayer(p);
long numWalls;
file >> numWalls;
for (int i = 0; i < numWalls; i++)
{
Wall* w = loadWall(file);
level->addStatic(w);
}
long numSwitches;
file >> numSwitches;
for (int i = 0; i < numSwitches; i++) {
float x, y;
int add;
int numAffectedWalls;
file >> x; file >> y; file >> add; file >> numAffectedWalls;
Switch* s = new Switch(x, y, add);
for (int j = 0; j < numAffectedWalls; j++) {
Wall* w = loadWall(file);
if (!add)
level->addStatic(w);
s->addObject(w);
}
level->addStatic(s);
}
long numWells;
file >> numWells;
for (int i = 0; i < numWells; i++)
{
float x, y;
bool positive;
file >> x;
file >> y;
file >> positive;
level->addPermanentWell(new GravityWell(x,y,positive));
}
level->setMaxGravityWells(maxWells);
file.close();
}