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


C++ Missile::getEnemyTarget方法代码示例

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


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

示例1: playerMissUpdate

//////// Missile locks on to closest enemy in front of player ////////
//////// Missile tracks enemy aggressively                    ////////
void AI::playerMissUpdate(Missile &proj, std::list<Enemy> *enemies, GSP420::ABC *player)
{
	// If missile has no target, get one
	if (proj.getEnemyTarget() == NULL)
	{
		float closestY = -100.0f;
		// Search through the enemy list for the one closest
		// to the player within a set field of view
		std::list<Enemy>::iterator enemyIt = enemies->begin();
		while (enemyIt != enemies->end())
		{
			if (enemyIt->getPosition().x > player->getPosition().x - 5.0f &&
				enemyIt->getPosition().x < player->getPosition().x + 5.0f &&
				enemyIt->getPosition().y > closestY)
			{
				closestY = enemyIt->getPosition().y;
				proj.setEnemyTarget(&*enemyIt);
			}

			enemyIt++;
		}
	}
	else // Otherwise track the enemy target
	{
		D3DXVECTOR3 newVel;
		Enemy *enemy = proj.getEnemyTarget();

		// Find the updated direction for the missile based on enemy position
		newVel = enemy->getPosition() - proj.getPosition();
		D3DXVec3Normalize(&newVel, &newVel);

		// Multiply direction vector by missile speed to obtain missile velocity
		newVel *= ENEMY_MISSILE_SPEED;
		proj.setVelocity(newVel);
	}
}
开发者ID:mblake90,项目名称:GSP420EngineDemo,代码行数:38,代码来源:AI.cpp


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