Exemplo n.º 1
0
        /************************************************************************/
        /* XNA Methods                                                          */
        /************************************************************************/
        public void update(GameTime gameTime)
        {
            TimeBetweenUpdates += gameTime.ElapsedGameTime.Milliseconds;

            float randomNumberX;
            float randomNumberY;

            // Adds the correct amount of particles to the list
            if (currentNumberOfParticles < NumberOfParticles)
            {
                if (TimeBetweenUpdates > TimeBetweenParticles)
                {
                    Vector2 prevVelocity = Velocity;

                    if (RandomDirection)
                    {
                        randomNumberX = NextFloat(random);
                        randomNumberY = NextFloat(random);

                        velocity.X = randomNumberX;
                        velocity.Y = randomNumberY;
                    }
                    else
                    {
                        if (Velocity.X != 0)
                        {
                            randomNumberX = (float)random.NextDouble();
                            if (randomNumberX < 0.5f)
                                velocity.X += (float)random.NextDouble();
                            else if (randomNumberX >= 0.5f)
                                velocity.X -= (float)random.NextDouble();
                        }

                        if (Velocity.Y != 0)
                        {
                            randomNumberY = (float)random.NextDouble();
                            if (randomNumberY < 0.5f)
                                velocity.Y += (float)random.NextDouble();
                            else if (randomNumberY >= 0.5f)
                                velocity.Y -= (float)random.NextDouble();
                        }
                    }

                    Particle tempParticle = new Particle(Texture, Position, Velocity, Life, 1.0f, true);

                    particles.Add(tempParticle);

                    CurrentNumberOfParticles++;

                    TimeBetweenUpdates++;

                    Velocity = prevVelocity;
                }
            }

            for (int i = 0; i < particles.Count(); i++)
            {
                particles[i].update(gameTime);

                if (particles[i].TotalLife > particles[i].Life)
                    particles.RemoveAt(i);
            }

            if (particles == null)
                IsActive = false;
        }
Exemplo n.º 2
0
        /************************************************************************/
        /* XNA Methods                                                          */
        /************************************************************************/
        public void update(GameTime gameTime, Vector2 position, Vector2 velocity)
        {
            LifeTimer += gameTime.ElapsedGameTime.Milliseconds;
            TimeBetweenUpdates += gameTime.ElapsedGameTime.Milliseconds;

            // Only uses the velocity passed in from the call if the lifespan is 0, eg if the emitter is attached to an object.
            //  This is not final behavior, but it works for now
            if (lifespan == 0)
                Velocity = velocity;

            Position = position;

            float randomNumberX;
            float randomNumberY;

            if (lifespan > LifeTimer || lifespan == 0)
            {
                if (TimeBetweenUpdates > TimeBetweenParticles)
                {
                    Vector2 prevVelocity = Velocity;

                    if (RandomDirections)
                    {
                        randomNumberX = NextFloat(random);
                        randomNumberY = NextFloat(random);

                        velocity.X = randomNumberX;
                        velocity.Y = randomNumberY;
                    }
                    else
                    {
                        if (Velocity.X != 0)
                        {
                            randomNumberX = random.Next(1, 3);
                            if (randomNumberX == 1)
                                velocity.X += 0.2f;
                            else if (randomNumberX == 2)
                                velocity.X -= 0.2f;
                        }

                        if (Velocity.Y != 0)
                        {
                            randomNumberY = random.Next(1, 3);
                            if (randomNumberY == 1)
                                velocity.Y += 0.2f;
                            else if (randomNumberY == 2)
                                velocity.Y -= 0.2f;
                        }
                    }

                    Particle tempParticle = new Particle(Texture, Position, Velocity, Life, 1.0f, true);

                    particles.Add(tempParticle);

                    TimeBetweenUpdates = 0;

                    Velocity = prevVelocity;
                }
            }

            for (int i = 0; i < particles.Count(); i++)
            {
                particles[i].update(gameTime);

                if (particles[i].TotalLife > particles[i].Life)
                    particles.RemoveAt(i);
            }

            if (particles == null)
            {
                IsActive = false;
            }
        }