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


C++ Aircraft::getWorldPosition方法代码示例

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


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

示例1: guideMissiles

void World::guideMissiles()
{
    // Setup command that stores all enemies in mActiveEnemies
	Command enemyCollector;
	enemyCollector.category = Category::EnemyAircraft;
	enemyCollector.action = derivedAction<Aircraft>([this] (Aircraft& enemy, sf::Time)
	{
	    if(!enemy.isDestroyed())
		{
		    mActiveEnemies.push_back(&enemy);
		}
	});
	
	// Setup command that guides all missiles to the enemy which is currently closest to the player
	Command missileGuider;
	missileGuider.category = Category::AlliedProjectile;
	missileGuider.action = derivedAction<Projectile>([this] (Projectile& missile, sf::Time)
	{
	    // Ignore unguided bullets
		if(!missile.isGuided())
		{
		    return;
		}
		
		float minDistance = std::numeric_limits<float>::max();
		Aircraft* closestEnemy = nullptr;
		
		// Find closest enemy
		for(Aircraft* enemy : mActiveEnemies)
		{
	        float enemyDistance = distance(missile, *enemy);
			
			if(enemyDistance < minDistance)
			{
			    closestEnemy = enemy;
			    minDistance = enemyDistance;
			}
		}
		
		if(closestEnemy)
		{
		    missile.guideTowards(closestEnemy->getWorldPosition());
		}
	});
	
	// Push commands, reset active enemies
	mCommandQueue.push(enemyCollector);
	mCommandQueue.push(missileGuider);
	mActiveEnemies.clear();
}
开发者ID:jimmybeer,项目名称:TAGEngine,代码行数:50,代码来源:World.cpp

示例2: guideMissiles

void World::guideMissiles()
{
    Command enemyCollector;
    enemyCollector.category = Category::EnemyAircraft;
    enemyCollector.action = derivedAction<Aircraft>(
            [this](Aircraft& enemy, sf::Time)
                {
                    if(!enemy.isDestroyed())
                        mActiveEnemies.push_back(&enemy);
                });
    Command missileGuider;
    missileGuider.category = Category::AlliedProjectile;
    missileGuider.action = derivedAction<Projectile>(
            [this](Projectile& missile, sf::Time)
                 {
                     if(!missile.isGuided())
                         return;
                     float minDistance = std::numeric_limits<float>::max();
                     Aircraft* closestEnemy = nullptr;
                     
                     for(auto* enemy : mActiveEnemies)
                     {
                         float enemyDistance = distance(missile, *enemy);
                         
                         if(enemyDistance < minDistance)
                         {
                             closestEnemy = enemy;
                             minDistance = enemyDistance;
                         }
                     }
                     if (closestEnemy)
                     {
                         missile.guideTowards(closestEnemy->getWorldPosition());
                     }
                 });
    mCommandQueue.push(enemyCollector);
    mCommandQueue.push(missileGuider);
    mActiveEnemies.clear();
}
开发者ID:kevin5396,项目名称:Hellfire,代码行数:39,代码来源:World.cpp


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