本文整理汇总了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;
}
}
示例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 );
//.........这里部分代码省略.........