コード例 #1
0
ファイル: bullet.cpp プロジェクト: Domix24/Cube
bool Bullet::CheckCollision(Character &character)
{
	if (m_isActive && character.GetisAlive())
	{
		int nbrIteration = 10;
		if (character.GetDimension().x <= character.GetDimension().y && character.GetDimension().x <= character.GetDimension().z)
			nbrIteration = ceil(m_vitesse.x / character.GetDimension().x);
		if (character.GetDimension().y <= character.GetDimension().x && character.GetDimension().y <= character.GetDimension().z)
			nbrIteration = ceil(m_vitesse.y / character.GetDimension().y);
		if (character.GetDimension().z <= character.GetDimension().y && character.GetDimension().z <= character.GetDimension().x)
			nbrIteration = ceil(m_vitesse.z / character.GetDimension().z);

		for (int i = 0; i < nbrIteration; i++)
		{
			if (m_LastPos.x + directionVector.x / nbrIteration * i >= character.GetPosition().x - character.GetDimension().x / 2
				&& m_LastPos.x + directionVector.x / nbrIteration * i < character.GetPosition().x + character.GetDimension().x / 2
				&& m_LastPos.y + directionVector.y / nbrIteration * i >= character.GetPosition().y
				&& m_LastPos.y + directionVector.y / nbrIteration * i < character.GetPosition().y + character.GetDimension().y
				&& m_LastPos.z + directionVector.z / nbrIteration * i >= character.GetPosition().z - character.GetDimension().z / 2
				&& m_LastPos.z + directionVector.z / nbrIteration * i < character.GetPosition().z + character.GetDimension().z / 2)
			{

				//f(x) = -1 * 1.02 ^ (x + 10) + 50
				character.GetDamage(-1 * pow(1.04, m_distance + 10) + m_damage);
				m_isActive = false;
				return true;
			}
		}
	}
	return false;
}
コード例 #2
0
//----------------------------------------------------------------------------
void SkillStepLink::OnEnter (SkillInstance *instance)
{
	SkillStep::OnEnter(instance);

	Skill *skill = instance->GetSkill();
	Character *character = skill->GetCharacter();
	Scene *scene = character->GetScene();
	Node *sceneNode = DynamicCast<Node>(scene->GetSceneNode());
	APoint charPos = character->GetPosition();

	int aimTarget = instance->GetAimTarget();
	Character *aimTargetChar = DynamicCast<Character>(scene->GetActorByID(
		aimTarget));
	if (aimTargetChar)
	{
		SkillActorLinkPtr skillActorLink = new0 SkillActorLink();

		instance->AddSkillActor(aimTarget, skillActorLink);

		skillActorLink->SetID(10000+scene->GetNextID());

		skillActorLink->Initlize();

		if (!mSelfEffectFilename.empty())
			skillActorLink->SetMovableFilename(mSelfEffectFilename);

		skillActorLink->SetFromActorID(character->GetID());
		skillActorLink->SetFromActorAnchor(mSelfEffectAnchor);

		if (IsLinkToActor())
		{
			skillActorLink->SetTargetType(SkillActorLink::TT_ACTOR);
			skillActorLink->SetToActorID(aimTarget);
		}
		else
		{
			APoint toPos = charPos + mLinkDir * mSpeed * mLinkToTime; 

			skillActorLink->SetTargetType(SkillActorLink::TT_POSITION);
			skillActorLink->SetToPosition(toPos);
		}

		skillActorLink->SetPosition(charPos);
		skillActorLink->SetLinkSpeed(GetSpeed());

		skillActorLink->ShowHelpMovable(false);

		scene->AddActor(skillActorLink);

		skillActorLink->Start();

		if (!mSelfPosEffectFilename.empty())
		{
			APoint pos = character->GetPosition();
			Transform trans;
			trans.SetTranslate(pos);
			trans.SetRotate(character->GetMovable()->WorldTransform.GetRotate());

			if (!mSelfPosEffectFilename.empty())
			{
				Node *anchor = character->GetAnchor(mSelfPosEffectAnchor);
				if (anchor)
				{
					//trans = anchor->WorldTransform;
					trans.SetTranslate(anchor->WorldTransform.GetTranslate());
				}
			}

			Object *obj = PX2_RM.BlockLoadShareCopy(mSelfPosEffectFilename, false,
				false, true);
			if (obj)
			{
				EffectNode *effectNode = DynamicCast<EffectNode>(obj);
				if (effectNode)
				{
					effectNode->SetSelfCtrled(true);
					effectNode->WorldTransform = trans;
					effectNode->WorldTransformIsCurrent = true;
					sceneNode->AttachChild(effectNode);
					effectNode->ResetPlay();

					PX2_DM.AddDeletingObj(effectNode, mSelfPosEffectTime, 3.0f);
				}
			}
		}
	}
	else
	{
		if (PX2_PROJ.IsInEditor())
		{
			SkillActorLinkPtr skillActorLink = new0 SkillActorLink();

			instance->AddSkillActor(aimTarget, skillActorLink);

			skillActorLink->SetID(10000+scene->GetNextID());

			skillActorLink->Initlize();

			if (!mSelfEffectFilename.empty())
				skillActorLink->SetMovableFilename(mSelfEffectFilename);

			skillActorLink->SetFromActorID(character->GetID());
			skillActorLink->SetFromActorAnchor(mSelfEffectAnchor);

			if (IsLinkToActor())
			{
				skillActorLink->SetTargetType(SkillActorLink::TT_ACTOR);
				skillActorLink->SetToActorID(aimTarget);
			}
			else
			{
				APoint toPos = charPos + mLinkDir * mSpeed * mLinkToTime; 

				skillActorLink->SetTargetType(SkillActorLink::TT_POSITION);
				skillActorLink->SetToPosition(toPos);
			}

			skillActorLink->SetPosition(charPos);
			skillActorLink->SetLinkSpeed(GetSpeed());

			skillActorLink->ShowHelpMovable(false);

			scene->AddActor(skillActorLink);

			skillActorLink->Start();
		}
		else
		{
			// over
		}
	}
}