⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 weaponfx.cpp

📁 Blood 2全套源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
				sp.fDuration		= 2.0f;
			}
			else
			{
				sp.nSparks			= (m_fDamage < 50.0f) ? (DBYTE)(m_fDamage * 2.0f): 100;
				sp.fDuration		= 0.5f;
			}
			break;

		// Specific variable values just for flesh surfaces
		case	SURFTYPE_FLESH:
			VEC_MULSCALAR(sp.vDir, m_vNormal, 50.0f);
			VEC_SET(sp.vColor1, 192.0f, 0.0f, 0.0f);
			VEC_SET(sp.vColor2, 255.0f, 0.0f, 0.0f);

			sprintf(str, "spritetextures\\particles\\blooddrop_%d.dtx", GetRandom(1,NRES(4)));
			sp.hstrTexture = m_pClientDE->CreateString(str);
			sp.nSparks			= (m_fDamage < 50.0f) ? (DBYTE)(m_fDamage * 4.0f) : 200;
			sp.fDuration		= 2.0f;
			sp.fEmissionRadius	= 5.0f;
			sp.fRadius			= 200.0f;
			sp.fGravity			= -150.0f;
			break;
	}

	psfxMgr->CreateSFX(SFX_SPARKS_ID, &sp, DFALSE, this);
	m_pClientDE->FreeString(sp.hstrTexture);
}

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CWeaponFX::CreateFragments
//
//	PURPOSE:	Creates pieces of a surface that fly off when shot
//
// ----------------------------------------------------------------------- //

void CWeaponFX::CreateFragments()
{
	CSFXMgr* psfxMgr = g_pBloodClientShell->GetSFXMgr();
	if(!psfxMgr) return;

	SURFFRAGCREATESTRUCT	sfcs;
	DFLOAT		randVal;
	DVector		temp, vU, vR, vF;
	m_pClientDE->GetRotationVectors(&m_rRotation, &vU, &vR, &vF); 

	VEC_COPY(sfcs.vNormal, m_vNormal);
	VEC_COPY(sfcs.vPos, m_vDestPos);
	VEC_SET(sfcs.vDecel, 0.0f, 0.0f, 0.0f);
	VEC_SET(sfcs.vScale, 0.05f, 0.05f, 0.0f);
	sfcs.fOffset = 3.0f;
	sfcs.fDuration = 3.0f;
	sfcs.bFade = 0;
	sfcs.bMove = 1;

	if(m_vNormal.y > 0.5)
		{	VEC_MULSCALAR(sfcs.vVel, m_vNormal, 3.0f); sfcs.fDuration = 2.0f;	}
	else
		{	VEC_COPY(sfcs.vVel, m_vNormal);	}


	switch(m_eSurfaceType)
	{
		case	SURFTYPE_WOOD:
		{
			sfcs.nType = 0;
			sfcs.bRotate = 1;

			if(IsLiquid(m_eDestCode))
				{	VEC_SET(sfcs.vGravity, 0.0f, -0.1f, 0.0f);	}
			else
				{	VEC_SET(sfcs.vGravity, 0.0f, -0.2f, 0.0f);	}

			for(char i = GetRandom(1,3); i > 0; i--)
			{
				randVal = GetRandom(-2.0f, 2.0f);
				if(randVal != 0.0f)
				{
					VEC_MULSCALAR(temp, vR, randVal);
					VEC_ADD(sfcs.vVel, sfcs.vVel, temp);
				}
				randVal = GetRandom(-2.0f, 3.0f);
				if(randVal != 0.0f)
				{
					VEC_MULSCALAR(temp, vU, randVal);
					VEC_ADD(sfcs.vVel, sfcs.vVel, temp);
				}

				psfxMgr->CreateSFX(SFX_FRAGMENTS_ID, &sfcs, DFALSE, this);
			}
			break;
		}
		case	SURFTYPE_STONE:
		{
			sfcs.nType = 1;
			sfcs.bRotate = 1;
			VEC_SET(sfcs.vScale, 0.03f, 0.03f, 0.0f);

			if(IsLiquid(m_eDestCode))
				{	VEC_SET(sfcs.vGravity, 0.0f, -0.15f, 0.0f);	}
			else
				{	VEC_SET(sfcs.vGravity, 0.0f, -0.3f, 0.0f);	}

			for(char i = GetRandom(1,3); i > 0; i--)
			{
				randVal = GetRandom(-2.0f, 2.0f);
				if(randVal != 0.0f)
				{
					VEC_MULSCALAR(temp, vR, randVal);
					VEC_ADD(sfcs.vVel, sfcs.vVel, temp);
				}
				randVal = GetRandom(-2.0f, 3.0f);
				if(randVal != 0.0f)
				{
					VEC_MULSCALAR(temp, vU, randVal);
					VEC_ADD(sfcs.vVel, sfcs.vVel, temp);
				}

				psfxMgr->CreateSFX(SFX_FRAGMENTS_ID, &sfcs, DFALSE, this);
			}
			break;
		}
		default:
			return;
	}
}

// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CWeaponFX::CreateShakeNFlash
//
//	PURPOSE:	Create a screen Flash/shake effect
//
// ----------------------------------------------------------------------- //

void CWeaponFX::CreateShakeNFlash()
{
	CSFXMgr* psfxMgr = g_pBloodClientShell->GetSFXMgr();
	if (!psfxMgr) return;

	// If we can see explosion, tint/shake screen...
	DVector vFlashColor;
	DVector vShake;
	DFLOAT fRampUp, fRampDown, fFlashTime, fRange, fShakeRange, fShakeTime;

	VEC_SET(vFlashColor, 0.7f, 0.7f, 0.7f);
	VEC_SET(vShake, 2.0f, 2.0f, 2.0f);

	fRampUp		= 0.1f;
	fRampDown	= 0.2f;
	fFlashTime	= 0.1f;
	fRange		= 500.0f;
	fShakeRange	= 1200.0f;
	fShakeTime	= 1.0f;

	DVector vCamPos;
	m_pClientDE->GetObjectPos(g_pBloodClientShell->GetCameraObj(), &vCamPos);

	// Determine if we should flash the screen...
	DVector vDir;
	VEC_SUB(vDir, m_vDestPos, vCamPos);
	DFLOAT fDist = VEC_MAG(vDir);
	if (fDist <= fRange)
	{
		// Adjust Flash for distance/angle of view

		DRotation rRot;
		DVector vU, vR, vF;
		m_pClientDE->GetObjectRotation(g_pBloodClientShell->GetCameraObj(), &rRot);
		m_pClientDE->GetRotationVectors(&rRot, &vU, &vR, &vF);

		VEC_NORM(vDir);
		VEC_NORM(vF);
		DFLOAT fMul = VEC_DOT(vDir, vF);
		if (fMul > 0.0f)
		{
			// Adjust for distance
			fMul *= (1 - fDist/fRange); 
			VEC_MULSCALAR(vFlashColor, vFlashColor, fMul);

			g_pBloodClientShell->FlashScreen(&vFlashColor, fRampUp, fFlashTime);
		}
	}

	// Determine if we should shake the screen...
	HLOCALOBJ hPlayerObj = m_pClientDE->GetClientObject();
	if (hPlayerObj)
	{
		DVector vPlayerPos;//, vPos;
		m_pClientDE->GetObjectPos(hPlayerObj, &vPlayerPos);

		VEC_SUB(vDir, vPlayerPos, m_vDestPos);
		DFLOAT fDist = VEC_MAG(vDir);

		if (fDist <= fShakeRange)
		{
			DFLOAT fMul = (1 - fDist/fShakeRange); 

			VEC_MULSCALAR(vShake, vShake, fMul);
			g_pBloodClientShell->ShakeScreen(&vShake, fShakeTime);
		}
	}
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CWeaponFX::CreateExplosion
//
//	PURPOSE:	Create an explosion effect
//
// ----------------------------------------------------------------------- //

void CWeaponFX::CreateExplosion()
{
	CSFXMgr* psfxMgr = g_pBloodClientShell->GetSFXMgr();
	if (!psfxMgr) return;

	EXPLOSIONFXCS expCS;

	expCS.hServerObj = 0;
	VEC_COPY(expCS.vPos, m_vDestPos);
	VEC_COPY(expCS.vNormal, m_vNormal);
	expCS.nType = m_nExplosionType;

	psfxMgr->CreateSFX(SFX_EXPLOSIONFX_ID, &expCS, DFALSE, this);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CWeaponFX::CreateImpactLight
//
//	PURPOSE:	Create an explosion effect
//
// ----------------------------------------------------------------------- //

void CWeaponFX::CreateImpactLight()
{
	CSFXMgr* psfxMgr = g_pBloodClientShell->GetSFXMgr();
	if (!psfxMgr) return;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CWeaponFX::CreateSplash
//
//	PURPOSE:	Create an explosion effect
//
// ----------------------------------------------------------------------- //

void CWeaponFX::CreateSplash()
{
	CSFXMgr* psfxMgr = g_pBloodClientShell->GetSFXMgr();
	if (!psfxMgr) return;

	SPLASHCREATESTRUCT		splcs;
	RIPPLECREATESTRUCT		ripcs;

	splcs.hServerObj = 0;
	VEC_COPY(splcs.vPos, m_vDestPos);
	VEC_COPY(splcs.vDir, m_vNormal);
	splcs.fRadius		= 100.0f;
	splcs.fPosRadius	= 1.0f;
	splcs.fHeight		= 175.0f;
	splcs.fDensity		= 4.0f;
	splcs.fSpread		= 10.0f;
	VEC_COPY(splcs.vColor1, m_vColor1);
	VEC_COPY(splcs.vColor2, m_vColor2);
	splcs.fSprayTime	= 0.3f;
	splcs.fDuration		= 0.75f;
	splcs.fGravity		= -500.0f;
	splcs.hstrTexture	= m_pClientDE->CreateString("spritetextures\\drop32_1.dtx");

	psfxMgr->CreateSFX(SFX_SPLASH_ID, &splcs, DFALSE, this);

	ripcs.hServerObj = 0;
	VEC_COPY(ripcs.vPos, m_vDestPos);
	VEC_COPY(ripcs.vNormal, m_vNormal);
	ripcs.fDuration = 1.0f;
	VEC_SET(ripcs.vMinScale, 0.1f, 0.1f, 0.0f);
	VEC_COPY(ripcs.vMaxScale, ripcs.vMinScale);
	ripcs.fInitAlpha = 0.25f;
	ripcs.bFade = 0;

	psfxMgr->CreateSFX(SFX_RIPPLE_ID, &ripcs, DFALSE, this);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CWeaponFX::CreateFlash
//
//	PURPOSE:	Create an explosion effect
//
// ----------------------------------------------------------------------- //

void CWeaponFX::CreateFlash()
{
	CSFXMgr* psfxMgr = g_pBloodClientShell->GetSFXMgr();
	if (!psfxMgr || IsLiquid(m_eDestCode))	return;

	EXPLOSIONSPRITECS	esCS;

	char	str[128];
	sprintf(str, "Sprites\\impact0%d.spr", GetRandom(1,NRES(5)));

	VEC_ADD(esCS.vPos, m_vDestPos, m_vNormal);
	VEC_COPY(esCS.vNormal, m_vNormal);
	VEC_SET(esCS.vScale1, 0.1f, 0.1f, 0.0f);
	VEC_SET(esCS.vScale2, 0.1f, 0.1f, 0.0f);
	esCS.fDuration		= 0.15f;
	esCS.fAlpha			= 1.0f;
	esCS.bWaveForm		= 0;
	esCS.bFadeType		= 0;
	esCS.bAlign			= 0;
	esCS.szSprite		= m_pClientDE->CreateString(str);

	psfxMgr->CreateSFX(SFX_EXPLOSIONSPRITE_ID, &esCS, DFALSE, this);
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CWeaponFX::CreateParticleTrail
//
//	PURPOSE:	Create an explosion effect
//
// ----------------------------------------------------------------------- //

void CWeaponFX::CreateParticleTrail()
{
	CSFXMgr* psfxMgr = g_pBloodClientShell->GetSFXMgr();
	if (!psfxMgr) return;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CWeaponFX::CreateMuzzleLight
//
//	PURPOSE:	Create an explosion effect
//
// ----------------------------------------------------------------------- //

void CWeaponFX::CreateMuzzleLight()
{
	CSFXMgr* psfxMgr = g_pBloodClientShell->GetSFXMgr();
	if (!psfxMgr) return;
}


// ----------------------------------------------------------------------- //
//
//	ROUTINE:	CWeaponFX::CreateTracer
//
//	PURPOSE:	Create a tracer fx
//
// ----------------------------------------------------------------------- //

void CWeaponFX::CreateTracer()
{
	CBloodClientShell *pShell = (CBloodClientShell*)g_pClientDE->GetClientShell();
	if (!pShell) return;

	CSFXMgr* psfxMgr = pShell->GetSFXMgr();
	if (!psfxMgr) return;

	DVector vF;

	VEC_COPY(vF, m_vDir);
	VEC_NORM(vF);
	VEC_MULSCALAR(vF, vF, 100.0f);

	TRACERCREATESTRUCT tr;

	tr.hServerObj = DNULL;
	VEC_COPY(tr.vVel, vF);

	VEC_SET(tr.vStartColor, 1.0f, 0.8f, 0.0f);
	VEC_SET(tr.vEndColor,   1.0f, 0.0f, 0.0f);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -