예제 #1
0
void CIdleEnemy::Update(float fElapsedTime)
{
	CBaseEnemy::Update(fElapsedTime);

	if(GetCurrentHP() <= 0)
		ChangeAIState(iDead);
	else
	{
		tVector2D Result;
		Result.fX = GetTargetPosition().fX - GetPosX();
		Result.fY = GetTargetPosition().fY - GetPosY();

		int Distance = int(sqrt(Result.fX*Result.fX + Result.fY*Result.fY));

		if(Distance <= GetSightRange())
		{
			ChangeAIState(iActive);
		}
		else
			ChangeAIState(Idle);
	}
	if( ReturnAIState() == iDead )
	{
	}
}
예제 #2
0
void CActionTarget::GetMainTarget(MAINTARGET* pRtMainTarget)
{
	switch(m_TargetKind)
	{
	case eActionTargetKind_None:
		ASSERTMSG(0,"GetTargetID is Called, When TargetKind is None");
		break;
		
	case eActionTargetKind_Object:
		{
			pRtMainTarget->MainTargetKind = MAINTARGET::MAINTARGETKIND_OBJECTID;

			CObject* pObject = OBJECTMGR->GetObject(m_TargetID);
			if(pObject == NULL)
			{
				pRtMainTarget->dwMainTargetID = 0;
				return;
			}			
			pRtMainTarget->dwMainTargetID = pObject->GetID();
			
			VECTOR3 pos;

			pObject->GetPosition( &pos );
		}
		break;

	case eActionTargetKind_Position:
		{
			pRtMainTarget->MainTargetKind = MAINTARGET::MAINTARGETKIND_POS;
			pRtMainTarget->cpTargetPos.Compress(GetTargetPosition());
		}
		break;
	}	
}
예제 #3
0
bool DeliverWaterAction::IsInRange()
{
	DL_ASSERT_EXP(myStockpileToDeliverTo != nullptr, "Invalid TargetEntity");

	CU::Vector2<float> ownPosition = myEntity.GetPosition();
	CU::Vector2<float> otherPosition = GetTargetPosition();
	CU::Vector2<float> direction = otherPosition - ownPosition;
	float distance = CU::Length(direction);

	if (distance < 10.f)
		return true;

	return false;
}
예제 #4
0
void CActionTarget::ConvertMainTargetToPosition(CObject* pAttacker,float AttackDist)
{
	VECTOR3 pos = *GetTargetPosition();
	VECTOR3 apos;
	pAttacker->GetPosition(&apos);
	float dist = CalcDistanceXZ(&pos,&apos);
	if(dist > AttackDist)
	{
		float gap = dist - AttackDist + 50.f;	// 50은 그냥 오차가 있을지 모르니 준것
		VECTOR3 dir = apos - pos;
		Normalize(&dir,&dir);
		dir = dir * gap;
		pos = pos + dir;
	}
	InitActionTarget(&pos,m_TargetFlag);
}
예제 #5
0
void CPatrolEnemy::Update(float fElapsedTime)
{
	CBaseEnemy::Update(fElapsedTime);

	if(GetCurrentHP() <= 0)
		ChangeAIState(pDead);
	else
	{
		tVector2D Result;
		Result.fX = GetTargetPosition().fX - GetPosX();
		Result.fY = GetTargetPosition().fY - GetPosY();

		float Distance = sqrt(Result.fX*Result.fX + Result.fY*Result.fY);

		if(Distance <= GetSightRange())
		{
			ChangeAIState(pActive);
			this->ReturnAIState();
		}
		else
			ChangeAIState(Patrol);

		switch(ReturnAIState())
		{
		case Patrol:
			{
				SetPosX((GetPosX() + GetBaseVelX() * fElapsedTime));

				if(GetPosX() <= 0)
				{
					SetPosX(0);
					SetCurrentDist(0);
					SetSpeed(-1*GetSpeed());
				}

				SetCurrentDist(GetCurrentDist() + (fabs(GetBaseVelX()) * fElapsedTime));

				if(GetCurrentDist() >= GetMaxDist())
				{
					SetCurrentDist(0);
					SetSpeed(-1*GetSpeed());
				}

				SetBaseVelX(GetBaseVelX() + GetSpeed() * fElapsedTime);

				if(GetBaseVelX() > 50)
					SetBaseVelX(50);
				else if(GetBaseVelX() < -50)
					SetBaseVelX(-50);
			}
			break;
		case pActive:
			{
				SetSpeed(-1*GetSpeed());
				SetBaseVelX(0);
			}
			break;
		case pDead:
			{
			}
			break;
		};
	}
}