当前位置: 首页>>代码示例>>C++>>正文


C++ Switch::addObject方法代码示例

本文整理汇总了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();
  }
开发者ID:jmslocum16,项目名称:platformer,代码行数:96,代码来源:LevelLoader.cpp


注:本文中的Switch::addObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。