Пример #1
0
void TBird::Escape()
{
	if ((LEFT_ESCAPE_POINT - m_tPos).Length() < (RIGHT_ESCAPE_POINT - m_tPos).Length())
	{
		TGfxVec2 tDirection = LEFT_ESCAPE_POINT - m_tPos;
		tDirection = tDirection.SquaredLength() >= 0.001f ? tDirection.Normalize() : TGfxVec2(0.0f, 0.0f);

		m_eDirection = tDirection.x >= 0.0f ? EDirection_Right : EDirection_Left;

		m_tVelocity = tDirection * (m_fSpeed * ((GfxTimeGetMilliseconds() - float(m_iLastMove)) / SECONDS));
		m_iLastMove = GfxTimeGetMilliseconds();
	}

	else
	{
		TGfxVec2 tDirection = RIGHT_ESCAPE_POINT - m_tPos;
		tDirection = tDirection.SquaredLength() >= 0.001f ? tDirection.Normalize() : TGfxVec2(0.0f, 0.0f);

		m_eDirection = tDirection.x >= 0.0f ? EDirection_Right : EDirection_Left;

		m_tVelocity = tDirection * (m_fSpeed * ((GfxTimeGetMilliseconds() - float(m_iLastMove)) / SECONDS));
		m_iLastMove = GfxTimeGetMilliseconds();
	}

	m_pTarget->SetPosition(m_tPos);
	m_pTarget->SetFallVelocity(0.f);

	if (m_tPos.x < LEFT_ESCAPE_POINT.x + (EMPTY_SPACE_RANGE/2.0f))
	{
		m_pTarget->SetAction(EAction_Idle);
		FindTarget();
		m_eAction = EBirdAction_ToTarget;
	}

	if (m_tPos.x > RIGHT_ESCAPE_POINT.x - (EMPTY_SPACE_RANGE / 2.0f))
	{
		m_pTarget->SetAction(EAction_Idle);
		FindTarget();
		m_eAction = EBirdAction_ToTarget;
	}
}
Пример #2
0
void TBird::GoToTarget()
{
	if (m_pTarget != nullptr && m_pTarget->GetAction() != EAction_Grab)
	{
		TGfxVec2 tDirection = m_pTarget->GetPos() - m_tPos;
		tDirection = tDirection.SquaredLength() >= 0.001f ? tDirection.Normalize() : TGfxVec2(0.0f, 0.0f);

		m_eDirection = tDirection.x >= 0.0f ? EDirection_Right : EDirection_Left;

		m_tVelocity = tDirection * (m_fSpeed * ((GfxTimeGetMilliseconds() - float(m_iLastMove)) / SECONDS));
		m_iLastMove = GfxTimeGetMilliseconds();

		if (m_pTarget->IsMouseOver(m_tPos))
		{
			m_pTarget->SetAction(EAction_Grab);
			m_pTarget->SetPosition(m_tPos);
			m_eAction = EBirdAction_DelivringTarget;
		}
	}
	else
	{
		FindTarget();
	}
}