Ejemplo n.º 1
0
        public void updateParticles()
        {
            if (!active)
            {
                return;
            }
            if (particlecount <= 0)
            {
                return;
            }

            for (int i = 0; i < maxNum; i++)
            {
                //particles[i] = new Particle();
                if (particles[i].active)
                {
                    particles[i].AgeInTicks++;
                    if (particles[i].AgeInTicks > particles[i].maxAgeInTicks)
                    {
                        particles[i].active = false;
                        particlecount--;
                    }
                    particles[i].vel = particles[i].vel + particles[i].delta;
                    particles[i].vel = particles[i].vel + windDelta;
                    particles[i].vel = particles[i].vel * resistance;

                    if (moveTowards == 3)
                    {
                        // 3 = towards moveTowardsPos
                        Vector2 v = (moveTowardsPos - particles[i].pos);
                        v.Normalize();
                        particles[i].vel = particles[i].vel + (v * moveToDrift);
                    }

                    if (moveTowards == 4)
                    {
                        // 4 = away from moveTowardsPos
                        Vector2 v = (particles[i].pos - moveTowardsPos);
                        v.Normalize();
                        particles[i].vel = particles[i].vel + (v * moveToDrift);
                    }


                    // CUSTOM
                    particles[i].vel *= 0.99f;

                    //particles[i].vel = particles[i].vel + (randomDelta*new Vector2((float)rnd.NextDouble(), (float)rnd.NextDouble())-randomDelta/2);
                    particles[i].oldPos.X = particles[i].pos.X;
                    particles[i].oldPos.Y = particles[i].pos.Y;
                    particles[i].pos      = particles[i].pos + particles[i].vel;
                    if (setDisplayAngle)
                    {
                        float a = Util.getAngle(particles[i].pos, particles[i].oldPos);
                        particles[i].displayAngle = a + displayAngleOffset;
                    }
                    //if (particles[i].bounds != null)
                    //{
                    if (!particles[i].bounds.Contains(new Point((int)particles[i].pos.X, (int)particles[i].pos.Y)))
                    {
                        particles[i].active = false;
                        particlecount--;
                    }
                    //}
                }
            }
        }
Ejemplo n.º 2
0
        public void makeParticles(int num)
        {
            if (!generation || !active)
            {
                return;                         //no more particles to generate
            }
            if (particlecount >= maxNum)
            {
                return;                          // no posibility of making particls
            }
            int     cnt = 0;
            Vector2 randy; // for varous random things

            for (int i = 0; i < maxNum; i++)
            {
                //particles[i] = new Particle();
                if (!particles[i].active)
                {
                    // make one here
                    particles[i].tex    = tex;
                    particles[i].active = true;
                    if (Origin == 0)
                    {
                        particles[i].pos.X = sysPos.X; //position
                        particles[i].pos.Y = sysPos.Y; //position
                    }
                    if (Origin == 1)
                    {
                        particles[i].pos.X = originRectangle.X + originRectangle.Width * (float)rnd.NextDouble();  //position
                        particles[i].pos.Y = originRectangle.Y + originRectangle.Height * (float)rnd.NextDouble(); //position
                    }
                    if (Origin == 2)
                    {
                        WayPoint wp = originWayList.getWayPoint(originWayList.getCurrentLeg());
                        originWayList.nextLeg();
                        particles[i].pos.X = wp.pos.X; //position
                        particles[i].pos.Y = wp.pos.Y; //position
                    }
                    if (Origin == 3)
                    {
                        int      q  = rnd.Next(originWayList.lst.Count());
                        WayPoint wp = originWayList.getWayPoint(q);
                        particles[i].pos.X = wp.pos.X; //position
                        particles[i].pos.Y = wp.pos.Y; //position
                    }

                    particles[i].vel = initialVelosity; //velocity
                    // add random bit
                    randy              = (new Vector2((float)rnd.NextDouble(), (float)rnd.NextDouble()) * initialVelosityRandom - (initialVelosityRandom / 2));
                    particles[i].vel   = particles[i].vel + randy;
                    particles[i].delta = delta + (randomDelta * new Vector2((float)rnd.NextDouble(), (float)rnd.NextDouble()) - randomDelta / 2);

                    if (initalAngleHigh != 0)
                    {
                        //set a radial velocity
                        float angle    = rnd.Next((int)initalAngleLow, (int)initalAngleHigh);
                        float velocity = rnd.Next((int)(initalVelocityLow * 100), (int)(initalVelocityHigh * 100)) / 100.0f;

                        Vector2 v = Util.moveByAngleDist(new Vector2(0, 0), Util.degToRad(angle), velocity);
                        particles[i].vel = v;
                    }

                    particles[i].startSize            = startSize;
                    particles[i].endSize              = endSize;
                    particles[i].startColor           = startColor;
                    particles[i].endColor             = endColor;
                    particles[i].bounds               = bounds; // my bounds
                    particles[i].AgeInTicks           = 0;
                    particles[i].maxAgeInTicks        = ticksParticleDuration;
                    particles[i].destRectangle.X      = (int)particles[i].pos.X;
                    particles[i].destRectangle.Y      = (int)particles[i].pos.Y;
                    particles[i].destRectangle.Width  = (int)particles[i].startSize.X;
                    particles[i].destRectangle.Height = (int)particles[i].startSize.Y;

                    if (moveTowards == 1)
                    {
                        // 0= nix  1= towards moveTowardsPos
                        particles[i].vel   = ((moveTowardsPos - particles[i].pos) / (float)ticksParticleDuration) + randy;
                        particles[i].delta = new Vector2(0, 0); // usually you want this
                    }

                    if (moveTowards == 2)
                    {
                        // 0= nix  1= towards moveTowardsPos
                        Vector2 v = (particles[i].pos - moveTowardsPos);
                        v.Normalize();
                        particles[i].vel   = (v * moveToDrift) + randy;
                        particles[i].delta = new Vector2(0, 0); // usually you want this
                    }


                    cnt++;
                    particlecount++;
                    totalNumberMade++;
                    if (totalNumberMade >= totalNumberToMake)
                    {
                        return;
                    }
                    if (cnt >= num)
                    {
                        return;         // done them all
                    }
                    if (particlecount >= maxNum)
                    {
                        return;                      // no more possible
                    }
                }
            }
        }