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


C++ CLine::x方法代码示例

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


在下文中一共展示了CLine::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;
    }
}
开发者ID:mgosemath,项目名称:cowsandbullsjee,代码行数:99,代码来源:AHAI.cpp


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