本文整理汇总了C++中vec2::GetDistanceSqTo方法的典型用法代码示例。如果您正苦于以下问题:C++ vec2::GetDistanceSqTo方法的具体用法?C++ vec2::GetDistanceSqTo怎么用?C++ vec2::GetDistanceSqTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类vec2
的用法示例。
在下文中一共展示了vec2::GetDistanceSqTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CheckEngaged
void Lieutenant::CheckEngaged()
{
engaged = false;
for (size_t i(0); i < marines.size(); ++i)
{
const Unit & marine(marines[i]);
// Cache the unit's position and the range of its weapon
const vec2 position(marine.GetPosition());
const sint4 range(marine.GetWeaponRange());
const sint4 rangeSq(range*range);
//Quick Check
if (marine.InCombat() && marine.IsAlive())
{
engaged = true;
return;
}
for(size_t j(0); j<enemies.size(); ++j)
{
const Unit & enemy(enemies[j]);
if(position.GetDistanceSqTo(enemy.GetPosition()) <= rangeSq)
{
engaged = true;
return;
}
}
}
for (size_t i(0); i < tanks.size(); ++i)
{
const Unit & tank(tanks[i]);
// Cache the unit's position and the range of its weapon
const vec2 position(tank.GetPosition());
const sint4 range(tank.GetWeaponRange());
const sint4 rangeSq(range*range);
//Quick Check
if (tank.InCombat() && tank.IsAlive())
{
engaged = true;
return;
}
for(size_t j(0); j<enemies.size(); ++j)
{
const Unit & enemy(enemies[j]);
if(position.GetDistanceSqTo(enemy.GetPosition()) <= rangeSq)
{
engaged = true;
return;
}
}
}
}
示例2: FireAtWill
void Lieutenant::FireAtWill(Vector<Unit> enemies)
{
for(size_t i(0); i<marines.size(); ++i)
{
sint4 weakestHP = 150; //tanks maxhealth
Unit& marine(marines[i]);
Unit& target = enemies[0];
// Cache the unit's position and the range of its weapon
const vec2 position(marine.GetPosition());
const sint4 range(marine.GetWeaponRange());
const sint4 rangeSq(range*range);
// Choose the weakest enemy unit we find in range
for(size_t j(0); j<enemies.size(); ++j)
{
const Unit & enemy(enemies[j]);
if(position.GetDistanceSqTo(enemy.GetPosition()) <= rangeSq)
{
sint4 hp = enemy.GetHitpoints();
if (hp <= weakestHP && hp > 0)
{
weakestHP = hp;
target = enemy;
}
}
}
if(position.GetDistanceSqTo(target.GetPosition()) <= rangeSq)
{
marine.Attack(target);
engaged = true;
}
}
for(size_t i(0); i<tanks.size(); ++i)
{
sint4 weakestHP = 150; //tanks maxhealth
Unit& tank(tanks[i]);
Unit& target = enemies[0];
// Cache the unit's position and the range of its weapon
const vec2 position(tank.GetPosition());
const sint4 range(tank.GetWeaponRange());
const sint4 rangeSq(range*range);
// Choose the weakest enemy unit we find in range
for(size_t j(0); j<enemies.size(); ++j)
{
const Unit & enemy(enemies[j]);
if(position.GetDistanceSqTo(enemy.GetPosition()) <= rangeSq)
{
sint4 hp = enemy.GetHitpoints();
if (hp <= weakestHP && hp > 0)
{
weakestHP = hp;
target = enemy;
}
}
}
if(position.GetDistanceSqTo(target.GetPosition()) <= rangeSq)
{
tank.Attack(target);
engaged = true;
}
}
}