Esempio n. 1
0
        public Explosive(Explosive other)
        {
            center_of_object = new Point3D(other.center_of_object.GetPoint().X, other.center_of_object.GetPoint().Y, other.center_of_object.GetZ());
            velocity         = new double[3];
            acceleration     = new double[3];

            Array.Copy(other.velocity, velocity, 3);
            Array.Copy(other.acceleration, acceleration, 3);
            max_age = 50;

            color = Color.FromArgb(other.color.A, other.color.R, other.color.G, other.color.B);
            size  = other.size;
            age   = other.age;
        }
Esempio n. 2
0
        public override List <Particle> Die()
        {
            List <Particle> pieces = new List <Particle>();

            if (tracer)
            {
                return(pieces);
            }

            Random rand = new Random(DateTime.Now.Millisecond);

            double degrees = 360 / num_pieces;

            if (degrees == 0.0)
            {
                double temp = 360 / Convert.ToDouble(num_pieces);

                while (temp < 1)
                {
                    temp *= 10.0;
                }

                degrees = Convert.ToInt32(temp);
            }

            double percent = rand.NextDouble();

            while (percent < 0.5)
            {
                percent = rand.NextDouble();
            }

            for (int i = 0; i < num_pieces; i++)
            {
                double val = rand.Next(1, 50);

                double velx = (val * percent) * Math.Cos(Math.PI * degrees * i / 180.0);
                double vely = (val * percent) * Math.Sin(Math.PI * degrees * i / 180.0);

                //"explode" particles in 360 degrees around the center point all with varying initial velocities in X & Y directions
                Explosive exp = new Explosive(center_of_object.GetPoint().X, center_of_object.GetPoint().Y, 0, 0, -9.8, velx, vely);
                pieces.Add(exp);
            }

            return(pieces);
        }
        public bool UpdateSystem(Graphics g, int w = 0, int h = 0)
        {
            height = h;
            width  = w;
            pixels = new int[height, width]; //all initialized to 0 which equates to black

            bool drawn = false;

            //if there are no particles in the system - nothing to do
            if (particles.Count == 0)
            {
                frame = 0;
                return(false);
            }

            List <Particle> dead_items = new List <Particle>();
            List <Particle> new_items  = new List <Particle>();

            for (int i = particles.Count - 1; i >= 0; i--)
            {
                Particle part = particles[i];
                //no change in acceleration
                part.Move(0.0, 0.0);

                int aging_factor = 1;
                if (part.GetTracer())
                {
                    aging_factor = 3;
                }

                part.AgeParticle(aging_factor);

                part.Draw(g);
                if (save_images)
                {
                    if (part.Draw(height, width, pixels))
                    {
                        drawn = true;
                    }
                }

                if (!part.IsAlive())
                {
                    List <Particle> items = part.Die();
                    dead_items.Add(part);
                    if (items != null)
                    {
                        foreach (var particle in items)
                        {
                            new_items.Add(particle);
                        }
                    }
                }
            }

            //walk the particles looking to see if they have tracers
            List <Particle> aged_particles = new List <Particle>();

            foreach (var part in particles)
            {
                if (part.LeaveTrace())
                {
                    Rocket rock = part as Rocket;
                    if (rock != null)
                    {
                        if (!rock.GetTracer())
                        {
                            Rocket temp = new Rocket(rock);
                            temp.SetTracer(true);
                            temp.Slow();
                            aged_particles.Add(temp);
                        }
                    }
                    else
                    {
                        Explosive exp = part as Explosive;
                        if (!exp.GetTracer())
                        {
                            Explosive temp = new Explosive(exp);
                            temp.SetTracer(true);
                            temp.Slow();
                            aged_particles.Add(temp);
                        }
                    }
                }
            }

            if (dead_items.Count > 0)
            {
                foreach (var deadItem in dead_items)
                {
                    particles.Remove(deadItem);
                }
            }

            if (new_items.Count > 0)
            {
                foreach (var particle in new_items)
                {
                    particles.Add(particle);
                }
            }

            if (aged_particles.Count > 0)
            {
                foreach (var particle in aged_particles)
                {
                    particles.Add(particle);
                }
            }

            if (save_images && drawn)
            {
                ColorManipulation manip = new ColorManipulation();
                manip.H = height;
                manip.W = width;

                string file_name = string.Format("particle_{0,4:D4}_{1}.png", frame, animation);
                manip.SaveToImage(pixels, file_name);
                frame++;
            }

            if (particles.Count == 0)
            {
                animation++;
            }

            return(true);
        }