void CHuman::Update(float fElapsedTime)
{
	CEnemy::Update( fElapsedTime );

	m_nCollisionWithStaticObjectsSphere.m_Center = tVector2D(GetPosX(), GetPosY());


	for( unsigned int i = 0; i < CGamePlayState::GetInstance()->m_StoreWalls.size(); i++)
	{
		Capsule* temp = CGamePlayState::GetInstance()->m_StoreWalls[i];
		tVector2D ClosestPoint = ClosestPointOnALine(temp->GetStartPoint(), temp->GetEndPoint(), tVector2D( GetPosX(), GetPosY()));

		// Create a circle based on clsoest point with capsule radius
		Circle testCircle;
		testCircle.m_Center = ClosestPoint;
		testCircle.m_fRadius = temp->GetRadius();

		if( GetSphere()->CheckCollision(testCircle) )
		{
			tVector2D sphere2_to_1 = GetSphere()->m_Center - testCircle.m_Center;
			sphere2_to_1 = Vector2DNormalize(sphere2_to_1);
			float dist = GetSphere()->m_fRadius + testCircle.m_fRadius;
			tVector2D scaler = (sphere2_to_1 * (dist * 0.01f));
			tVector2D newpos = GetSphere()->m_Center + scaler;

			SetPosX(newpos.fX);
			SetPosY(newpos.fY);
		}
	}
}
void CGuard::Update(float fElapsedTime)
{

	if(CheckForPlayer())
	{
		ComputeMovement(fElapsedTime);
		this->addTime(fElapsedTime);
		CBase::Update(fElapsedTime);
	}
	else
		CEnemy::Update( fElapsedTime );

	m_nCollisionWithStaticObjectsSphere.m_Center = tVector2D(GetPosX(), GetPosY());


	for( unsigned int i = 0; i < CGamePlayState::GetInstance()->m_StoreWalls.size(); i++)
	{
		Capsule* temp = CGamePlayState::GetInstance()->m_StoreWalls[i];
		tVector2D ClosestPoint = ClosestPointOnALine(temp->GetStartPoint(), temp->GetEndPoint(), tVector2D( GetPosX(), GetPosY()));

		// Create a circle based on clsoest point with capsule radius
		Circle testCircle;
		testCircle.m_Center = ClosestPoint;
		testCircle.m_fRadius = temp->GetRadius();

		if( GetSphere()->CheckCollision(testCircle) )
		{
			tVector2D sphere2_to_1 = GetSphere()->m_Center - testCircle.m_Center;
			sphere2_to_1 = Vector2DNormalize(sphere2_to_1);
			float dist = GetSphere()->m_fRadius + testCircle.m_fRadius;
			tVector2D scaler = (sphere2_to_1 * (dist * 0.01f));
			tVector2D newpos = GetSphere()->m_Center + scaler;

			SetPosX(newpos.fX);
			SetPosY(newpos.fY);
		}
	}

	if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_1))
	{
		IsUndead = true;
		AnimManager::GetInstance()->SetAnimation( GetAnimID(), "Zombie Walking" );
	}
	if( CSGD_DirectInput::GetInstance()->KeyPressed(DIK_2))
	{
		IsUndead = false;
		AnimManager::GetInstance()->SetAnimation( GetAnimID(), "Person Walking" );
	}
}