Exemplo n.º 1
0
        private void initParticle(Particle particle)
        {
            var cache = RandomCaches();

            particle.System = this;

            particle.Position.X = (int) ( Position.X + PositionRandom.X * Random() );
            particle.Position.Y = (int) ( Position.Y + PositionRandom.Y * Random() );

            var newAngle = ( Angle + AngleRandom * Random() ) * ( Math.PI / 180 ); // convert to radians
            var vector = new DoublePoint(Math.Cos(newAngle), Math.Sin(newAngle)); // Could move to lookup for speed
            var vectorSpeed = Speed + SpeedRandom * Random();
            particle.Direction = vector.Multiply(vectorSpeed);

            particle.Size = cache.Size;
            particle.Size = particle.Size < 0 ? 0 : ~~(int) particle.Size;
            particle.TimeToLive = cache.TimeToLive;

            particle.Sharpness = cache.Sharpness;
            particle.Sharpness = particle.Sharpness > 100 ? 100 : particle.Sharpness < 0 ? 0 : particle.Sharpness;
            // internal circle gradient size - affects the sharpness of the radial gradient
            particle.SizeSmall = (int) ( ( particle.Size / 200 ) * particle.Sharpness ); //(size/2/100)

            double[] start = cache.Start;

            double[] end = cache.End;

            particle.Color = start;
            particle.DeltaColor[0] = ( end[0] - start[0] ) / particle.TimeToLive;
            particle.DeltaColor[1] = ( end[1] - start[1] ) / particle.TimeToLive;
            particle.DeltaColor[2] = ( end[2] - start[2] ) / particle.TimeToLive;
            particle.DeltaColor[3] = ( end[3] - start[3] ) / particle.TimeToLive;

            particle.BuildCache(1, cache);

            if (Game.DebugText[1].Falsey())
                Game.DebugText[1] = 0;
            Game.DebugText[1] = (int) Game.DebugText[1] + 1;
        }
Exemplo n.º 2
0
        private object obtainGradient(CanvasContext2D context, Particle particle)
        {
            var halfSize = (int) particle.Size >> 1;

            /*   string key = halfSize + particle.DrawColor + particle.SizeSmall;
            if (grads.ContainsKey(key)) {
                return grads[key];
            }*/

            if (Game.DRAWFAST)
                return particle.DrawColor;

            var radgrad = context.CreateRadialGradient(halfSize, halfSize, particle.SizeSmall, halfSize, halfSize, halfSize);
            //var radgrad = context.CreateLinearGradient(halfSize, halfSize, particle.SizeSmall, halfSize);
            radgrad.AddColorStop(0, particle.DrawColor);
            radgrad.AddColorStop(1, particle.DrawColorTransparent); //Super cool if you change these values (and add more Color stops)
            return /*grads[key]=*/ radgrad;
        }
Exemplo n.º 3
0
        public Particle AddParticle()
        {
            if (Particles.Count == MaxParticles) return null;

            if (tick++ % curRand == 0) {
                caches[(int) ( ( caches.Count - 1 ) * Math.Random() )] = newCache();
                curRand = (int) ( Math.Random() * 100 );
            }

            // Take the next particle out of the particle pool we have created and initialize it
            var particle = new Particle();
            initParticle(particle);
            Particles.Add(particle);
            // Increment the particle count
            return particle;
        }