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


C++ Ball::GetCntrY方法代码示例

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


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

示例1: Game_Main

void Game_Main()
{
   HDC hdc = GetDC(g_hwnd);
   RECT rect;
   Ball* ball = NULL;
   static Archnoid::USHORT birthRate = 0;

   // white out the playing bounds
   GetClientRect(g_hwnd,&rect);
   FillRect(g_hdcBuffer,&rect,(HBRUSH)GetStockObject(WHITE_BRUSH));
   
   // draw the playing bounds
   SelectObject( g_hdcBuffer, GetStockObject( WHITE_BRUSH ) );
   Rectangle(g_hdcBuffer, g_gameArea.GetWestWall(), g_gameArea.GetNorthWall(), 
                          g_gameArea.GetEastWall(), g_gameArea.GetSouthWall());

   //g_blockCollection.RandomMoveAll();
   //g_blockCollection.RandomGravitateToCenterAll();
   // HAUKAP - which ball to gravitate to?
   g_blockCollection.RandomGravitateToPointAll( g_balls.GetFirstBall()->GetCntrX(), g_balls.GetFirstBall()->GetCntrY() );

   if( ++birthRate >= GamePlayDefaults::RESPAWN_RATE )
   {
      birthRate = 0;
      g_blockCollection.NewGenerations();
   }
   
   ball = g_balls.GetFirstBall();
   while( ball )
   {
      ball->Move();

      // did ball go out of bounds?
      CollisionType collision = g_gameArea.OutOfBounds(*ball);
      if( !collision )
      {
         // did ball collide with one of the blocks?
         collision = g_blockCollection.IsCollision(*ball);
      }

      if( collision )
      {
         ball->UnMove();
         if( VERTICAL_COLLISION(collision) )
            ball->ResolveCollision(Vertical);
         else if( HORIZONTAL_COLLISION(collision) )
            ball->ResolveCollision(Horizontal);
      }

      ball = g_balls.GetNextBall();
   }


      
   // draw the blocks   
   SelectObject( g_hdcBuffer, GetStockObject( LTGRAY_BRUSH ) );
   const Block* block = g_blockCollection.GetFirstBlock();
   while( block )
   {
      switch(BlockDefaults::SHAPE)
      {
      case ShapeCircle: 
         Ellipse(g_hdcBuffer, block->GetX(), block->GetY(),
                              block->GetX() + block->GetWidth(),
                              block->GetY() + block->GetHeight());
         break;
      case ShapeRect: 
         Rectangle(g_hdcBuffer,block->GetX(),block->GetY(),
                               block->GetX()+block->GetWidth(),
                               block->GetY()+block->GetHeight());
         break;
      default: assert(!"invalid shape");
      }
      block = g_blockCollection.GetNextBlock();
   }

   // draw the ball
   SelectObject( g_hdcBuffer, GetStockObject( BLACK_BRUSH ) );
   ball = g_balls.GetFirstBall();
   while( ball )
   {
      Ellipse( g_hdcBuffer, ball->GetULX(), ball->GetULY(),
                            ball->GetLRX(), ball->GetLRY());
      ball = g_balls.GetNextBall();
   }

   // draw debug/info text
   const char escMsg[] = "Hit any key to exit";
   TextOut(g_hdcBuffer,5,5,escMsg, (int)strlen(escMsg));


   char buf[256];
   std::string buf1( "Blocks: " );
   buf1 += _itoa_s( g_blockCollection.GetNumBlocks(), buf, 10);
   TextOut(g_hdcBuffer,5,20,buf1.c_str(), (int)buf1.size());

   Archnoid::USHORT y = 40;
   Archnoid::USHORT i = 1;
   ball = g_balls.GetFirstBall();
   while( ball )
//.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:101,代码来源:


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