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


C++ Vector2::Multiply方法代码示例

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


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

示例1: Update

void BannerBox::Update()
{
  double angleToTravel;
  Vector2* moveVector;

  if( CurrentPosition != TargetPosition )
  {
    angleToTravel = CurrentPosition->AngleTo( TargetPosition );
    moveVector = new Vector2( angleToTravel );
    moveVector->Multiply( 1.7 );
    CurrentPosition->Add( moveVector );
    if( abs(CurrentPosition->X - TargetPosition->X) <= 2.0 && abs(CurrentPosition->Y - TargetPosition->Y) <= 2.0 )
    {
      CurrentPosition->X = TargetPosition->X;
      CurrentPosition->Y = TargetPosition->Y;
    }

    delete moveVector;
  }
}
开发者ID:pmprog,项目名称:TournamentHub,代码行数:20,代码来源:bannerbox.cpp

示例2: Update

void Ball::Update()
{
	Vector2* prevPosition = new Vector2(ballPosition->X, ballPosition->Y);

	Vector2* v = new Vector2( ballDirection->ToDegrees() );
	v->Multiply( ballVelocity );
	ballPosition->Add( v );
	delete v;

	if( ballPosition->X < gameArena->Player1WallX )
	{
		ballPosition->X = gameArena->Player1WallX - (ballPosition->X - gameArena->Player1WallX);
		if( ballDirection->ToDegrees() < 180.0f )
		{
			ballDirection->Add( ballDirection->ShortestAngleTo(90.0f) * -2.0f );
		} else {
			ballDirection->Add( (270.0f - ballDirection->ToDegrees()) * 2.0f );
		}
		// Hurt Player 1
		if( gameArena->Player1 != 0 )
		{
			gameArena->Player1->TakeDamage( 2 );
		}
	}
	if( ballPosition->X >= gameArena->Player2WallX )
	{
		ballPosition->X -= ballPosition->X - gameArena->Player2WallX;
		if( ballDirection->ToDegrees() > 270.0f )
		{
			ballDirection->Add( ballDirection->ShortestAngleTo(270.0f) * -2.0f );
		} else {
			ballDirection->Add( 180.0f - (ballDirection->ToDegrees() * 2.0f) );
		}
		// Hurt player 2
		if( gameArena->Player2 != 0 )
		{
			gameArena->Player2->TakeDamage( 2 );
		}
	}
	if( ballPosition->Y < gameArena->RoofY )
	{
		ballPosition->Y = gameArena->RoofY - (ballPosition->Y - gameArena->RoofY);
		if( ballDirection->ToDegrees() < 270.0f )
		{
			ballDirection->Add( ballDirection->ShortestAngleTo(180.0f) * -2.0f );
		} else {
			ballDirection->Add( (360.0f - ballDirection->ToDegrees()) * 2.0f );
		}
	}
	if( ballPosition->Y >= gameArena->FloorY )
	{
		ballPosition->Y -= ballPosition->Y - gameArena->FloorY;
		if( ballDirection->ToDegrees() > 90.0f )
		{
			ballDirection->Add( ballDirection->ShortestAngleTo(180.0f) * 2.0f );
		} else {
			ballDirection->Add( 360.0f - (ballDirection->ToDegrees() * 2.0f) );
		}
	}

	// Check collisions with players
	Line* ballPath = new Line( prevPosition, ballPosition );
	Line* pArea = 0;
	bool ballAdjustXLeft;
	if( ballDirection->ToDegrees() > 90.0f && ballDirection->ToDegrees() < 270.0f && gameArena->Player1 != 0 )
	{
		ballPath->Points[0]->X -= ballRadius;
		ballPath->Points[1]->X -= ballRadius;
		ballAdjustXLeft = true;
		pArea = gameArena->Player1->GetCollisionLine();
	}
	if( (ballDirection->ToDegrees() < 90.0f || ballDirection->ToDegrees() > 270.0f) && gameArena->Player2 != 0 )
	{
		ballPath->Points[0]->X += ballRadius;
		ballPath->Points[1]->X += ballRadius;
		ballAdjustXLeft = false;
		pArea = gameArena->Player2->GetCollisionLine();
	}
	if( pArea != 0 )
	{
		Vector2* pContact = ballPath->GetIntersection( pArea );
		if( pContact != 0 )
		{
			/*
			if( ballDirection->ToDegrees() < 180.0f && ballDirection->ToDegrees() > 90.0f )
			{
				ballDirection->Add( ballDirection->ShortestAngleTo(90.0f) * -2.0f );
				ballPosition->X += (pContact->X - ballPosition->X) * 2.0f;
			} else if( ballDirection->ToDegrees() >= 180.0f && ballDirection->ToDegrees() < 270.0f ) {
				ballDirection->Add( (270.0f - ballDirection->ToDegrees()) * 2.0f );
				ballPosition->X += (pContact->X - ballPosition->X) * 2.0f;
			} else if( ballDirection->ToDegrees() > 270.0f ) {
				ballDirection->Add( ballDirection->ShortestAngleTo(270.0f) * -2.0f );
				ballPosition->X -= (ballPosition->X - pContact->X) * 2.0f;
			} else if( ballDirection->ToDegrees() < 90.0f ) {
				ballDirection->Add( 180.0f - (ballDirection->ToDegrees() * 2.0f) );
				ballPosition->X -= (ballPosition->X - pContact->X) * 2.0f;
			}
			*/
			Angle* a = pArea->Reflection( ballPath );
//.........这里部分代码省略.........
开发者ID:foxblock,项目名称:BattlePong,代码行数:101,代码来源:ball.cpp


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