Esempio n. 1
0
HRESULT CPartEmitter::AddForce(char *Name, CPartForce::TForceType Type, int PosX, int PosY, float Angle, float Strength) {
	CPartForce *Force = AddForceByName(Name);
	if (!Force) return E_FAIL;

	Force->m_Type = Type;
	Force->m_Pos = Vector2(PosX, PosY);

	Force->m_Direction = Vector2(0, Strength);
	Matrix4 MatRot;
	MatRot.RotationZ(DegToRad(CBUtils::NormalizeAngle(Angle - 180)));
	MatRot.TransformVector2(Force->m_Direction);

	return S_OK;
}
HRESULT CPartEmitter::InitParticle(CPartParticle* Particle, DWORD CurrentTime, DWORD TimerDelta)
{
	if(!Particle) return E_FAIL;
	if(m_Sprites.GetSize()==0) return E_FAIL;

	int PosX = CBUtils::RandomInt(m_PosX, m_PosX + m_Width);
	int PosY = CBUtils::RandomInt(m_PosY, m_PosY + m_Height);
	float PosZ = CBUtils::RandomFloat(0.0f, 100.0f);
	
	float Velocity;
	if(m_VelocityZBased) Velocity = m_Velocity1 + PosZ * (m_Velocity2 - m_Velocity1) / 100;
	else Velocity = CBUtils::RandomFloat(m_Velocity1, m_Velocity2);

	float Scale;
	if(m_ScaleZBased) Scale = m_Scale1 + PosZ * (m_Scale2 - m_Scale1) / 100;
	else Scale = CBUtils::RandomFloat(m_Scale1, m_Scale2);

	int LifeTime;
	if(m_LifeTimeZBased) LifeTime = m_LifeTime2 - PosZ * (m_LifeTime2 - m_LifeTime1) / 100;
	else LifeTime = CBUtils::RandomInt(m_LifeTime1, m_LifeTime2);
	
	float Angle = CBUtils::RandomAngle(m_Angle1, m_Angle2);	
	int SpriteIndex = CBUtils::RandomInt(0, m_Sprites.GetSize() - 1);

	float Rotation = CBUtils::RandomAngle(m_Rotation1, m_Rotation2);	
	float AngVelocity = CBUtils::RandomFloat(m_AngVelocity1, m_AngVelocity2);
	float GrowthRate = CBUtils::RandomFloat(m_GrowthRate1, m_GrowthRate2);

	if(!CBPlatform::IsRectEmpty(&m_Border))
	{
		int ThicknessLeft   = m_BorderThicknessLeft   - (float)m_BorderThicknessLeft   * PosZ / 100.0f;
		int ThicknessRight  = m_BorderThicknessRight  - (float)m_BorderThicknessRight  * PosZ / 100.0f;
		int ThicknessTop    = m_BorderThicknessTop    - (float)m_BorderThicknessTop    * PosZ / 100.0f;
		int ThicknessBottom = m_BorderThicknessBottom - (float)m_BorderThicknessBottom * PosZ / 100.0f;

		Particle->m_Border = m_Border;
		Particle->m_Border.left += ThicknessLeft;
		Particle->m_Border.right -= ThicknessRight;
		Particle->m_Border.top += ThicknessTop;
		Particle->m_Border.bottom -= ThicknessBottom;
	}

	Vector2 VecPos((float)PosX, (float)PosY);
	Vector2 VecVel(0, Velocity);

	Matrix4 MatRot;
	MatRot.RotationZ(DegToRad(CBUtils::NormalizeAngle(Angle - 180)));
	MatRot.TransformVector2(VecVel);

	if(m_AlphaTimeBased)
	{
		Particle->m_Alpha1 = m_Alpha1;
		Particle->m_Alpha2 = m_Alpha2;
	}
	else
	{
		int Alpha = CBUtils::RandomInt(m_Alpha1, m_Alpha2);
		Particle->m_Alpha1 = Alpha;
		Particle->m_Alpha2 = Alpha;		
	}

	Particle->m_CreationTime = CurrentTime;
	Particle->m_Pos = VecPos;
	Particle->m_PosZ = PosZ;
	Particle->m_Velocity = VecVel;
	Particle->m_Scale = Scale;
	Particle->m_LifeTime = LifeTime;
	Particle->m_Rotation = Rotation;
	Particle->m_AngVelocity = AngVelocity;
	Particle->m_GrowthRate = GrowthRate;
	Particle->m_ExponentialGrowth = m_ExponentialGrowth;
	Particle->m_IsDead = FAILED(Particle->SetSprite(m_Sprites[SpriteIndex]));
	Particle->FadeIn(CurrentTime, m_FadeInTime);


	if(Particle->m_IsDead) return E_FAIL;
	else return S_OK;
}