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


C++ Part::getActScript方法代码示例

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


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

示例1: activation

void Player::activation()
{
	float lowestDist = 90;
	bool partFound = false;
	Part* closestPart = NULL;
	int closestPartID;
	float partDist = lowestDist + 1;

	//Looping thru all of the parts
	for(int i = 0; i < world->getPartAmount(); i++)
	{
		if(world->getPartUsable(i) == 1) //Making sure we are only looking at parts that can actually be used
		{
			float partX = world->getPartX(i);
			float partY = world->getPartY(i);

			float distX = partX - x;
			float distY = partY - y;
			float dist = agk::Sqrt(distX * distX + distY * distY);

			int useRange = 90;
			if(dist < useRange) //Checking if the part is within reach
			{
				partFound = true;
				
				if(dist < lowestDist) //CHecking if this is the closest part found
				{
					lowestDist = dist; //Changing the lowest distance
					partDist = dist;

					closestPart = world->getPartFromID(i); //Changing the lowest part we have found
					closestPartID = i;
				}
			}
		}
	}

	bool npcFound = false;
	NPC* closestNPC = NULL;
	float npcDist = lowestDist + 1;
	
	//Looping thru all the NPCs (Using the)
	for(unsigned int i = 0; i < defaultNPCGroup->getNPCAmount(); i++)
	{
		NPC* npc = defaultNPCGroup->getNPC(i);

		if(npc != NULL)
		{
			float npcX = npc->getX();
			float npcY = npc->getY();

			float distX = npcX - x;
			float distY = npcY - y;
			float dist = agk::Sqrt(distX * distX + distY * distY);

			if(dist < lowestDist)
			{
				npcFound = true;

				lowestDist = dist;
				npcDist = dist;

				closestNPC = npc;
			}
		}
	}

	if((partFound == true && closestPart != NULL) || (npcFound == true && closestNPC != NULL))
	{
		if(partDist < npcDist)
		{
			//Positioning the activation text
			agk::SetTextVisible(activateText, 1);
			agk::SetTextPosition(activateText, agk::WorldToScreenX( closestPart->getX() ), agk::WorldToScreenY( closestPart->getY() ));

			//Changing the text to the use text of the part
			std::string fText;
			fText = i_activateName;
			fText.append(") ");
			fText.append(closestPart->getUseMsg());

			agk::SetTextString(activateText, fText.data());

			//Adding the background
			agk::SetSpritePosition(activateSprite, agk::WorldToScreenX(closestPart->getX()) -5.0f, agk::WorldToScreenY(closestPart->getY()) - 2.5f);
			agk::SetSpriteVisible(activateSprite, 1);
			agk::SetSpriteScale(activateSprite, agk::GetTextTotalWidth(activateText) + 10, agk::GetTextTotalHeight(activateText) + 5);

			//Checking if the part is activated
			if(Input::activate() == true)
			{
				//Getting the script of the item
				std::string actScript;
				actScript = ("scripts/");
				actScript.append(closestPart->getActScript());

				//Saving the part that was activated last for use with labels in lua
				world->setLastActive(closestPartID);

				//Checking if this is a lua script or an old script
//.........这里部分代码省略.........
开发者ID:TheZoq2,项目名称:Silverheart,代码行数:101,代码来源:Player.cpp


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