Beispiel #1
0
Emitter& Emitter::Update(float elapsed){
	if(_active){
		if(_particles.size() == 0 || (_continuous && _elapsedLastBirth >= .2)){
			_elapsedLastBirth = 0;
			for(int i = 0; i < 50; i++){
				Particle p;
				p.SetPosition(0, 0);
				float angle = RADIANS * (rand() % (_maxAngle - _minAngle) + _minAngle);
				int velocity = rand() % _radius;
				p.SetColor(_color);
				p.SetPositionDelta(sf::Vector2f(velocity * cos(angle), velocity * sin(angle)));
				p.SetFinalColor(sf::Color(255, 255, 255, 0));
				p.SetLifetime(_lifetime);
				p.SetCenter(0, 0);
				_particles.push_back(p);
			  }
		}
		vector<Particle>::iterator it;
		for(it = _particles.begin(); it < _particles.end(); it++){
			if(it->GetLifetime() <= it->GetAge()){
				_particles.erase(it);
			}
			else{
				it->Update(elapsed);
			}
		}
		
		if(_particles.size() == 0)
			this->_active = false;
		_elapsedLastBirth += elapsed;
	}
	return *this;
}
Beispiel #2
0
void Emitter::Update(double elapsed)
{

	Array <int> particlesToRemove;
	//eliminacion de particulas

	for( unsigned int i = 0; i < particles.Size(); i++ )
	{
		particles[i]->Update( elapsed );
		
		for( unsigned int a = 0; a < affectors.Size(); a++ ) affectors[a].AddParticles( particles[i] );
			
		if( particles[i]->GetLifetime() <= 0 )
		{
			particlesToRemove.Add( i );
			delete particles[i];
		
			for( unsigned int a = 0; a < affectors.Size(); a++ ) affectors[a].DeleteParticles( particles[i] );			
		}
	}

	for( int i = particlesToRemove.Size() - 1; i >= 0 ; i-- )
	{
		particles.RemoveAt( particlesToRemove[i] );
	}

	//fin eliminacion particulas

	//creacion de particulas

	int32 nParticles = 0;
	double velX, velY, velAng, life;
	uint8 r, g, b;

	if( IsEmitting() )
	{
		nParticles = static_cast<int32>( RangeRand( static_cast<int32>( minrate ), static_cast<int32>( maxrate ) ) * elapsed );
	}

	for( uint32 i = 0; i < (uint32)nParticles; i++ )
	{
		velX = RangeRand( minvelx, maxvelx );
		velY = RangeRand( minvely, maxvely ); 
		velAng = RangeRand( minangvel, maxangvel ); 
		life = RangeRand( minlifetime, maxlifetime) ;
		r = (uint8)RangeRand( minr, maxr );
		g = (uint8)RangeRand( ming, maxg );
		b = (uint8)RangeRand( minb, maxb );

		Particle *particle = new Particle( image, velX, velY, velAng, life, autofade );

		particle->SetPosition( x, y );
		particle->SetColor( r, g, b, 255 );
		particle->SetBlendMode( blendMode );

		particles.Add( particle );
	}
	//fin creacion particulas
}
Beispiel #3
0
Particle * Emitter::CreateParticle() const
{
	double velx, vely, angVel, lifetime;
	uint8 r, g, b;

	GenerateRandomProperties(velx, vely, angVel, lifetime, r, g, b);

	Particle* newParticle = new Particle(image, velx, vely,angVel,lifetime,autofade);
	
	newParticle->SetX(x);
	newParticle->SetY(y);
	newParticle->SetBlendMode(blendMode);
	newParticle->SetColor(r,g,b,255);

	return newParticle;
}
Beispiel #4
0
void Emitter::Update(double elapsed) {
    if (m_emitting) {
        double randVelX;
        double randVelY;
        double randAngVel;
        double randLifetime;
        double randRate = genRandomF(m_minrate, m_maxrate) * elapsed;

        //spawn
        uint8 randR, randG, randB;
        Particle p;
        for (unsigned short int i = 0; i < randRate; i++) {
            randVelX = genRandomF(m_minvelx, m_maxvelx);
            randVelY = genRandomF(m_minvely, m_maxvely);
            randAngVel = genRandomF(m_minangvel, m_maxangvel);
            randLifetime = genRandomF(m_minlifetime, m_maxlifetime);
            randR = genRandomF(m_minr, m_maxr);
            randG = genRandomF(m_ming, m_maxg);
            randB = genRandomF(m_minb, m_maxb);
            p = Particle(m_image, randVelX, randVelY, randAngVel, randLifetime, m_autofade);
            p.SetBlendMode(Renderer::BlendMode::ADDITIVE);
            p.SetColor(randR, randG, randB);
            p.SetPosition(m_x, m_y);
            m_particles.Add(p);
        }
    }
    //update
    for (unsigned short int i = 0; i < m_particles.Size(); i++) {
        if (!m_particles[i].Affected()) {
            for (unsigned short int j = 0; j < m_affectors.Size(); j++) {
                if (m_particles[i].GetX() >= m_affectors[j].GetX0() && m_particles[i].GetX() <= m_affectors[j].GetX1()
                        && m_particles[i].GetY() >= m_affectors[j].GetY0() && m_particles[i].GetY() <= m_affectors[j].GetY1()) {
                    m_affectors[j].ChangeParticleProperties(m_particles[i]);
                }
            }
        }
        if (m_particles[i].GetAlpha() == 0 || m_particles[i].GetLifeTime() <= 0) {
            m_particles.RemoveAt(i);
        } else
            m_particles[i].Update(elapsed);
    }
}
void Emitter::Update(double elapsed)
{
	Array<uint32> toDelete;

	if (emitting)
	{
		uint8 r = 0, g = 0, b = 0;
		double velx = 0, vely = 0;
		double angvel = 0;
		double lifetime = 0;

		// Incrementamos la lista de particulas.
		uint32 rate = (uint32)(Random(minrate, maxrate) * elapsed);
		for (uint32 i = 0; i < rate; i++)
		{
			r = (uint8)Random(minr, maxr);
			g = (uint8)Random(ming, maxg);
			b = (uint8)Random(minb, maxb);
			velx = Random(minvelx, maxvelx);
			vely = Random(minvely, maxvely);
			angvel = Random(minangvel, maxangvel);
			lifetime = Random(minlifetime, maxlifetime);
			Particle* p = new Particle(image, velx, vely, angvel, lifetime, autofade);
			p->SetBlendMode(blendMode);
			p->SetColor(r, g, b);
			p->SetPosition(x, y);
			particles.Add(p);
		}
	}

	// Actualizamos la lista de particulas y la lista de afectores.
	for (uint32 i = 0; i < particles.Size(); i++)
	{
		particles[i]->Update(elapsed);
		if (particles[i]->GetLifetime() <= 0)
			toDelete.Add(i);

		for (uint32 j = 0; j < affectors.Size(); j++)
		{
			if ( !affectors[j]->IsAffecting(particles[i]) && affectors[j]->InRange(particles[i]->GetX(), particles[i]->GetY()) )
			{
				if (affectors[j]->GetMode() & AffectorMode::ANG_VEL)
					particles[i]->SetAngVelocity(affectors[j]->GetAngularVelocity());
				if (affectors[j]->GetMode() & AffectorMode::VELOCITY)
					particles[i]->SetVelocity(affectors[j]->GetVelocityX(), affectors[j]->GetVelocityY());
				if (affectors[j]->GetMode() & AffectorMode::COLOR)
					particles[i]->SetColor(	affectors[j]->GetRed(), affectors[j]->GetGreen(),
											affectors[j]->GetBlue(), particles[i]->GetAlpha());
				affectors[j]->AddAffected(particles[i]);
			}
		}
	}

	// Eliminamos las particulas cuyo lifetime haya expirado.
	for (uint32 i = toDelete.Size(); 0 < i; i--)
	{
		for (uint32 j = 0; j < affectors.Size(); j++)
			if ( affectors[j]->IsAffecting(particles[toDelete[i-1]]) )
				affectors[j]->RemoveAffected(particles[toDelete[i-1]]);

		particles.RemoveAt(toDelete[i-1]);
	}
}