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


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

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


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

示例1: CollisionAction

void SpeedDownBox::CollisionAction(Ball & B)
{
	Vector ballSpeed = B.GetSpeed();
	ballSpeed.X *= SPEEDADD;
	ballSpeed.Y *= SPEEDADD;
	B.SetSpeed(ballSpeed);
}
开发者ID:deerel,项目名称:BallsToTheWall,代码行数:7,代码来源:SpeedDownBox.cpp

示例2: Game_Main


//.........这里部分代码省略.........
   // 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 )
   {
      sprintf_s( buf, "Ball[%d] [x:%d y:%d sp:%f vX:%f vY:%f]", i, 
               ball->GetCntrX(), ball->GetCntrY(),
               ball->GetSpeed(), ball->GetVectX(), ball->GetVectY() );
      TextOut(g_hdcBuffer, 5, y, buf, (int)strlen(buf) );

      ball = g_balls.GetNextBall();
      y += 15;
      ++i;
   }

   // copy the game area over to the main hdc
   BitBlt(hdc,0,0,g_gameArea.GetEastWall(),g_gameArea.GetSouthWall(),
          g_hdcBuffer,0,0,SRCCOPY);    

   ReleaseDC(g_hwnd,hdc);
   Sleep(GamePlayDefaults::SLEEPTIME);
}
开发者ID:,项目名称:,代码行数:101,代码来源:


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