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


C++ Enemy::getBulletFireRate方法代码示例

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


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

示例1:

/////// This enemy behavior seeks out the player ////////
/////// until they reach a set Y value at which  ////////
/////// point they simply fly straight.          ////////
void AI::enemy1Update(Enemy &enemy, GSP420::ABC *player, const float dt)
{
    // Check if enemy Y position is higher than half the game height
    if (enemy.getPosition().y > 0.0f) // TODO: Modify for exact game height constant
    {
        D3DXVECTOR3 tempVel;
        // Get new enemy direction based on player position
        tempVel = player->getPosition() - enemy.getPosition();
        D3DXVec3Normalize(&tempVel, &tempVel);

        // Multiply enemy direction by its speed to get its velocity
        tempVel *= ENEMY_SPEED;
        enemy.setVelocity(tempVel);
    }

    // Uncomment if needed
    //enemy.setPosition(enemy.getPosition() += enemy.getVelocity() * dt);

    // Check if enemy should fire a bullet
    float bFireRate = enemy.getBulletFireRate();
    enemy.setBulletFireRate(bFireRate -= dt);
    if (bFireRate <= 0.0f)
    {
        enemy.fireBullet(D3DXVECTOR3(0.0f, -5.0f, 0.0f)); // TODO: Modify for a fixed bullet speed constant
        enemy.setBulletFireRate(ENEMY_BULLET_FR);
    }
}
开发者ID:mblake90,项目名称:GSP420EngineDemo,代码行数:30,代码来源:AI.cpp

示例2: enemyBossUpdate

//////// Boss moves down into game screen ////////
//////// then begins its attack run       ////////
void AI::enemyBossUpdate(Enemy &enemy, const float dt)
{
    // Move into game screen
    if (enemy.getPosition() < D3DXVECTOR3(0.0f, 20.0f, 0.0f)) // TODO: Modify for constant Y position value
    {
        D3DXVECTOR3 vel = D3DXVECTOR3(0.0f, -5.0f, 0.0f);
        enemy.setVelocity(vel);
        // Uncomment if needed
        //enemy.setPosition(enemy.getPosition() += vel * dt);
    }
    else
    {
        // Begin attack run
        // Fire bullets
        float bFireRate = enemy.getBulletFireRate();
        enemy.setBulletFireRate(bFireRate -= dt);
        if (bFireRate <= 0.0f)
        {
            float x = -20.0f;
            for (int i = 0; i < 4; i++)
            {
                enemy.fireBullet(D3DXVECTOR3(x, -20.0f, 0.0f));
                x += 10.0f;
            }

            enemy.setBulletFireRate(1.0f);
        }

        // Fire missiles
        float missFireRate = enemy.getMissileFireRate();
        enemy.setMissileFireRate(missFireRate -= dt);
        if (missFireRate <= 0.0f)
        {
            enemy.fireMissile(D3DXVECTOR3(0.0f, -20.0f, 0.0f));
            enemy.setMissileFireRate(10.0f);
        }

        // Fire mines
        // Cannot specify where to drop mine
        // Mines are listed as a pickup, are they intended to be picked up by the player?
        /*float mineFireRate = enemy.getMineFireRate();
        enemy.setMineFireRate(mineFireRate -= dt);
        if (mineFireRate <= 0.0f)
        {

        }*/
    }
}
开发者ID:mblake90,项目名称:GSP420EngineDemo,代码行数:50,代码来源:AI.cpp


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