예제 #1
0
        public void initialize( string name, Vector3 position, Vector3 direction, Color color, float scaleModifier = 1.0f, int nParticlesModifier = 0, float lifetimeModifier = 0.0f)
        {
            particles.Clear();
            data = ParticleManager.Instance.getBaseParticleSystemData(name);
            this.position = position;
            this.direction = direction;

            // modify the base data with the parameters
            if (nParticlesModifier != 0)
            {
                data.nParticles = nParticlesModifier;
            }
            if (lifetimeModifier != 0.0f)
            {
                data.systemLife = lifetimeModifier;
                data.particlesLife = lifetimeModifier;
            }

            data.size *= scaleModifier;
            data.sizeIni *= scaleModifier;
            data.sizeEnd *= scaleModifier;
            data.positionVarianceMin *= scaleModifier;
            data.positionVarianceMax *= scaleModifier;
            data.directionVarianceMin *= scaleModifier;
            data.directionVarianceMax *= scaleModifier;
            data.accelerationVarianceMin *= scaleModifier;
            data.accelerationVarianceMax *= scaleModifier;
            data.color = new Color(data.color.ToVector4() * color.ToVector4());

            // get an aproximate number of the simultaneous particles that will have the system
            float spawnRatio = data.particlesLife / (float)data.nParticles;
            particles.Capacity = data.nParticles;

            switch(data.type)
            {
                case ParticleSystemData.tParticleSystem.Burst:
                    for(int i=0; i<data.nParticles; i++)
                    {
                        Particle p = new Particle();
                        p.isDead = true;
                        initializeParticle(p);
                        particles.Add(p);
                    }
                    break;
                case ParticleSystemData.tParticleSystem.Fountain:
                    for(int i=0; i<data.nParticles; i++)
                    {
                        Particle p = new Particle();
                        // we want particles prepared to be spawned with the spawnRatio ratio, so we set'em all alive but invisible
                        p.life = 1.3f + spawnRatio * i;
                        p.isDead = false;
                        p.color *= 0;
                        particles.Add(p);
                    }
                    break;
                default:
                    break;
            }
        }
예제 #2
0
파일: Game1.cs 프로젝트: steynh/GamingMinor
        void createParticles(string Texture, Vector2 Position, int HowMany, float Radius, float LifeTime, Color Color)
        {
            Vector2 _tmpPosition;

            Particle p;

            for (int i = 0; i < HowMany; i++) {
                double radius = Math.Sqrt(_randomizer.NextDouble()) * Radius;
                double angle = _randomizer.NextDouble() * Math.PI * 2;

                _tmpPosition.X = Position.X + (float)(radius * Math.Cos(angle));
                _tmpPosition.Y = Position.Y + (float)(radius * Math.Sin(angle));

                p = new Particle((float)(LifeTime * _randomizer.NextDouble()));
                p.Position = _tmpPosition;
                p.Texture = Texture;
                p.RotationOrigin = new Vector2(allTextures[Texture].Width / 2, allTextures[Texture].Height / 2);
                p.Rect = new Rectangle((int)p.Position.X, (int)p.Position.Y, allTextures[Texture].Width, allTextures[Texture].Height);
                p.Color = Color;
                allParticles.Add(p);
            }
        }
예제 #3
0
 void initializeParticle(Particle particle)
 {
     particle.size = data.sizeIni;
     Vector3 v = Calc.randomVector3(data.positionVarianceMin, data.positionVarianceMax);
     particle.position = position + data.position + v;
     v = Calc.randomVector3(data.directionVarianceMin, data.directionVarianceMax);
     particle.direction = direction + data.direction + v;
     v = Calc.randomVector3(data.accelerationVarianceMin, data.accelerationVarianceMax);
     particle.acceleration = data.acceleration + v;
     particle.rotation = data.particlesRotation + Calc.randomScalar(-data.particlesRotationVariance, data.particlesRotationVariance);
     particle.rotationSpeed = data.particlesRotationSpeed + Calc.randomScalar(-data.particlesRotationSpeedVariance, data.particlesRotationSpeedVariance);
     particle.baseColor = data.color;
     particle.baseColor.R += (byte)Calc.randomNatural(data.colorVarianceMin.R, data.colorVarianceMax.R);
     particle.baseColor.G += (byte)Calc.randomNatural(data.colorVarianceMin.G, data.colorVarianceMax.G);
     particle.baseColor.B += (byte)Calc.randomNatural(data.colorVarianceMin.B, data.colorVarianceMax.B);
     particle.baseColor.A += (byte)Calc.randomNatural(data.colorVarianceMin.A, data.colorVarianceMax.A);
     particle.life = data.particlesLife;
 }