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


C++ Guard::SetMoveSpeed方法代码示例

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


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

示例1: Update

void AttackState::Update(double dt)
{
	FSMState::Update(dt);

	Guard* g = dynamic_cast<Guard*>(m_FSMOwner);

	// Check if the NPC is legit
	if (!g)
	{
		return;
	}

	if (g->GetAttacked() && g->GetKnockedOut())
	{
		if (g->GetLastTarget())
		{
			g->GetLastTarget()->SetTargetted(false); // Tell spy that guard no longer has sight on it
		}
		else if (g->GetTarget())
		{
			g->GetTarget()->SetTargetted(false); // Tell spy that guard no longer has sight on it
		}
		g->SetMoveSpeed(Guard::S_GUARD_PATROL_SPEED);
		changeState(new AttackedState());
		return;
	}

	if (!g->GetTarget()) // Target missing
	{
		m_missingTimer += dt;
		if (g->GetLastTarget())
		{
			//g->GetLastTarget()->SetTargetted(false); // Tell spy that guard no longer has sight on it
		}
		if (!m_reached)
		{
			if (m_recordPoint)
			{
				g->AddToFallback(g->GetTransform().Translation);
				m_recordPoint = false;
			}
			moveToLastSeen(dt);
		}
		else
		{
			g->SetMoveSpeed(Guard::S_GUARD_PATROL_SPEED);
			g->GetView()->SetScale(Vector2(g->GetDefaultViewRadius() * 2.f, g->GetDefaultViewRadius() * 2.f));
			g->UpdateViewPosition();
			changeState(new PatrolState());
			return;
		}
	}
	else // Target still in sight
	{
		m_missingTimer = 0.f;
		m_recordPoint = true;
		g->GetTarget()->SetTargetted(true); // Tell spy that guard spotted it
		m_attackTimer += dt;
		if (m_attackTimer >= S_TIME_TILL_ATTACK)
		{
			int killChance = Math::RandIntMinMax(1, 100);
			if (killChance < 70) // % chance to kill spy
			{
				g->GetTarget()->Kill();
				g->GetTarget()->SetTargetted(false);
				g->SetMoveSpeed(Guard::S_GUARD_PATROL_SPEED);
				g->GetView()->SetScale(Vector2(g->GetDefaultViewRadius() * 2.f, g->GetDefaultViewRadius() * 2.f));
				g->UpdateViewPosition();

				changeState(new PatrolState());
				return;
			}
			m_attackTimer = 0.f;
		}
	}

	if (m_missingTimer >= S_MISSING_TIMER) // Can't find target for a period of time
	{
		if (g->GetLastTarget())
		{
			g->GetLastTarget()->SetTargetted(false); // Tell spy that guard no longer has sight on it
		}
		changeState(new PatrolState());
		g->GetView()->SetScale(Vector2(g->GetDefaultViewRadius() * 2.f, g->GetDefaultViewRadius() * 2.f));
		g->UpdateViewPosition();
		return;
	}
}
开发者ID:Pycorax,项目名称:AIAssignment2,代码行数:88,代码来源:AttackState.cpp


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