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


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

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


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

示例1: updateVision

//----------------------------- updateVision ----------------------------------
//
//  this method iterates through all the bots in the game world to test if
//  they are in the field of view. Each bot's memory record is updated
//  accordingly
//-----------------------------------------------------------------------------
void SensoryMemory::updateVision()
{
	const auto& elist = _owner->getGame()->getNeighborsOnMove(_owner->getWorldPosition(), _viewRange);

	for (auto iter = std::begin(elist); iter != std::end(elist); iter++)
	{
		if (_owner->getTag() != (*iter)->getTag())
		{
			if (isMasked((*iter)->getFamilyMask(), FamilyMask::HUMAN_BASE))
			{
				HumanBase* human = static_cast<HumanBase*>(*iter);

				//make sure it is part of the memory map
				makeNewRecordIfNotAlreadyPresent(human);

				//get a reference to this bot's data
				MemoryRecord& info = _memory[human];

				Vec2 ownerPos = _owner->getWorldPosition();
				Vec2 humanPos = human->getWorldPosition();

				if (ownerPos.getDistance(humanPos) < _viewRange)
				{
					info.isLosOkay = _owner->getGame()->isLOSOkay(ownerPos, humanPos);

					if (info.isLosOkay)
					{
						if (ownerPos.getDistance(humanPos) < _attackRange)
							info.attackable = true;
						else
							info.attackable = false;

						info.viewable = true;
						info.timeBecameVisible = info.timeLastSensed;
						info.timeLastSensed =
							system_clock::now().time_since_epoch();
						info.timeLastVisible =
							system_clock::now().time_since_epoch();
						info.lastSensedPos = humanPos;
					}
					else
					{
						info.attackable = false;
						info.viewable = false;
					}
				}
				else
				{
					info.attackable = false;
					info.viewable = false;
				}
			}
			else if (isMasked((*iter)->getFamilyMask(), FamilyMask::ITEM_BASE))
			{
				ItemBase* item = static_cast<ItemBase*>(*iter);
				if (_owner->getWorldPosition().getDistance(item->getWorldPosition()) < _viewRange)
				{
					auto finded = std::find(std::begin(_sensedItems), std::end(_sensedItems), item);

					if (finded == std::end(_sensedItems))
						_sensedItems.push_back(item);
				}
			}
		}
	}
}
开发者ID:Realtrick-Games,项目名称:DeadForest,代码行数:72,代码来源:SensoryMemory.cpp


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