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


C++ Platform::x方法代码示例

本文整理汇总了C++中Platform::x方法的典型用法代码示例。如果您正苦于以下问题:C++ Platform::x方法的具体用法?C++ Platform::x怎么用?C++ Platform::x使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Platform的用法示例。


在下文中一共展示了Platform::x方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addObjectsToPlatform

   void PlatformGenerator::addObjectsToPlatform(Platform& p, const Engine& e)
   {
      // Some constants
      const int MaxYounglingClusters = 4;
      const int MinYounglingClusters = 2;
      const int MaxYounglingsInCluster = 3;
      const int MinYounglingsInCluster = 3;

      if(p.x() > m_minBlockLength * 16) // don't add objects to the very first platform
      {
         // Add younglings.
         // Younglings come in groups of 1, 2 or 3.
         // There can be up to 4 groups of younglings on one platform
         // There's at least two groups on each platform.
         // They are positioned randomly.
         int clusters = MinYounglingClusters + rand() % (MaxYounglingClusters - MinYounglingClusters + 1);
         GameObjectPtr next_youngling(new Youngling(e, 0, 0));
         int max_cluster_width = next_youngling -> width() * MaxYounglingsInCluster;
         int yng_x = rand() % (p.width() - max_cluster_width); // X coordinate offset from the start of the platform
         int yng_y = p.y() - next_youngling -> height(); // Y coordinate

         // Place groups one after another, leaving some space between them. 
         // If we exceed the length of the platform, wrap around.
         for(int c = 0; c < clusters; ++c) // Generate younglings for each group
         {
            int yng_count = MinYounglingsInCluster + rand() % (MaxYounglingsInCluster - MinYounglingsInCluster + 1); 
            yng_x = (yng_x + max_cluster_width) % (p.width() - max_cluster_width);

            // Place each youngling in the group
            for(int c = 0; c < yng_count; ++c)
            {
               next_youngling.reset(new Youngling(e, p.x() + yng_x, yng_y));
               p.addObject(GameObjectPtr(next_youngling));
               yng_x += next_youngling -> width();
            }
         }

         // Add meanies.
         // Meanies come in the following combinations:
         // a single Walker
         // a single Jumper
         // Jumper - Walker
         // Jumper - Flyer
         // Walker - Flyer
         int r = rand() % 5;
         switch(r)
         {
         case 0:
            p.addObject(GameObjectPtr(new MeanWalker(e, p.x() + 16, p.y() - 9, p.x(), p.x() + p.width()))); 
            break;

         case 1:
            p.addObject(GameObjectPtr(new MeanJumper(e, p.x() + p.width()/2, p.y() - 10,  p.x(), p.x() + p.width())));
            break;

         case 2:
            p.addObject(GameObjectPtr(new MeanWalker(e, p.x() + 16, p.y() - 9, p.x(), p.x() + p.width()))); 
            p.addObject(GameObjectPtr(new MeanJumper(e, p.x() + p.width()/2, p.y() - 10,  p.x(), p.x() + p.width())));
            break;

         case 3:
            p.addObject(GameObjectPtr(new MeanFlyer(e, p.x() + p.width()/4, p.y() - 32,  p.x(), p.x() + p.width())));
            p.addObject(GameObjectPtr(new MeanWalker(e, p.x() + 16, p.y() - 9, p.x(), p.x() + p.width()))); 
            break;

         case 4:
            p.addObject(GameObjectPtr(new MeanFlyer(e, p.x() + p.width()/4, p.y() - 32,  p.x(), p.x() + p.width())));
            p.addObject(GameObjectPtr(new MeanJumper(e, p.x() + p.width()/2, p.y() - 10,  p.x(), p.x() + p.width())));
            break;
         }

         // Add a heart with 1/3 probability
         if(rand() % 3 == 0)
         {
            p.addObject(GameObjectPtr(new Heart(e, p.x() + rand() % p.width(), p.y() - (16 + rand() % 5))));
         }
      }
   }
开发者ID:10098,项目名称:braveball,代码行数:78,代码来源:platform_generator.cpp


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