本文整理汇总了C++中CLine::can_calculate_x方法的典型用法代码示例。如果您正苦于以下问题:C++ CLine::can_calculate_x方法的具体用法?C++ CLine::can_calculate_x怎么用?C++ CLine::can_calculate_x使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CLine
的用法示例。
在下文中一共展示了CLine::can_calculate_x方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: executePrepareShoot
void AHAI::executePrepareShoot()
{
AHPoint pPuckFuturePosition;
CLine* cShotLine;
float fTimeForThePuckToCome;
float fDistanceToTarget;
int iChoice;
switch(iStateStep)
{
case AH_STATE_STEP_ENTER:
// default: direct shot
pShotPoint = calculateGoalPoint();
iChoice = rand() % 2;
// with bounce
if(iChoice == 1)
{
// against the left wall
if(pMyPosition.x >= 0.0 && pPuckPosition.x < -fHoleToShoot)
pShotPoint.x -= AH_TABLE_WIDTH * (1 + rand() % 2); // one or two bounces
// against the right wall
else if(pMyPosition.x < 0.0 && pPuckPosition.x > fHoleToShoot)
pShotPoint.x += AH_TABLE_WIDTH * (1 + rand() % 2);
}
// puck's future position
fImpulseDistance = fBackSpace;
pPuckFuturePosition.y = pMyPosition.y + fImpulseDistance;
pPuckFuturePosition.x = predictPositionX(pPuckFuturePosition.y);
// shot line
cShotLine = new CLine(pShotPoint.x, pShotPoint.y, pPuckFuturePosition.x, pPuckFuturePosition.y);
pTargetPosition = pMyPosition;
if(cShotLine->can_calculate_x())
pTargetPosition.x = (float)cShotLine->x(pTargetPosition.y);
// speed
if(abs(vPuckVelocity.y) > fStopped)
{
fTimeForThePuckToCome = (pPuckFuturePosition.y - pPuckPosition.y) / vPuckVelocity.y;
fTimeForThePuckToCome = abs(fTimeForThePuckToCome);
fTimeForThePuckToCome -= 2.0; // state change frames
if(fTimeForThePuckToCome < 0.0)
{
fCalculatedSpeed = cLevel.SpeedForShooting;
}
else
{
fDistanceToTarget = (pTargetPosition.x - pMyPosition.x) * (pTargetPosition.x - pMyPosition.x);
fDistanceToTarget += (pTargetPosition.y - pMyPosition.y) * (pTargetPosition.y - pMyPosition.y);
fDistanceToTarget = sqrt(fDistanceToTarget);
fCalculatedSpeed = fDistanceToTarget / fTimeForThePuckToCome;
fCalculatedSpeed = min(cLevel.SpeedForShooting, fCalculatedSpeed);
}
}
else
{
fCalculatedSpeed = cLevel.DefaultSpeed;
}
iStateStep = AH_STATE_STEP_EXECUTE;
break;
case AH_STATE_STEP_EXECUTE:
fSpeed = fCalculatedSpeed;
if(targetPositionReached() || // ready for the shot
pPuckPosition.y <= pMyPosition.y || // the puck has escaped
pPuckPosition.y > (AH_TABLE_HEIGHT / 2) || // the puck is out of my zone
abs(vPuckVelocity.y) < fStopped) // the puck is stopped
{
iStateStep = AH_STATE_STEP_EXIT;
}
break;
case AH_STATE_STEP_EXIT:
if(pPuckPosition.y > pMyPosition.y)
selectState(AH_STATE_SHOOT_TO_GOAL);
else
selectState(AH_STATE_NOTHING);
break;
default:
break;
}
}