Example #1
0
        /// <summary>
        /// Updates the projectile.
        /// </summary>
        public bool Update(GameTime gameTime)
        {
            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            // Simple projectile physics.
            position   += velocity * elapsedTime;
            velocity.Y -= elapsedTime * gravity;
            age        += elapsedTime;

            // Update the particle emitter, which will create our particle trail.
            trailEmitter.Update(gameTime, position);

            // If enough time has passed, explode! Note how we pass our velocity
            // in to the AddParticle method: this lets the explosion be influenced
            // by the speed and direction of the projectile which created it.
            if (age > projectileLifespan)
            {
                for (int i = 0; i < numExplosionParticles; i++)
                {
                    explosionParticles.AddParticle(position, velocity);
                }

                for (int i = 0; i < numExplosionSmokeParticles; i++)
                {
                    explosionSmokeParticles.AddParticle(position, velocity);
                }

                return(false);
            }

            return(true);
        }
Example #2
0
        /// <summary>
        /// Helper for updating the fire effect.
        /// </summary>
        void UpdateFire()
        {
            const int fireParticlesPerFrame = 20;

            // Create a number of fire particles, randomly positioned around a circle.
            for (int i = 0; i < fireParticlesPerFrame; i++)
            {
                fireParticles.AddParticle(RandomPointOnCircle(), Vector3.Zero);
            }

            // Create one smoke particle per frmae, too.
            smokePlumeParticles.AddParticle(RandomPointOnCircle(), Vector3.Zero);
        }
Example #3
0
        void UpdateComic()
        {
            const int particlesPerFrame = 1;
            Vector3   heightVec         = new Vector3(0, 40, 0);

            // Create a number of fire particles, randomly positioned around a circle.
            for (int i = 0; i < particlesPerFrame; i++)
            {
                cF4DrillAirHit.AddParticle(RandomPointOnSphere(10f) + heightVec, Vector3.Zero);
            }

            // Create one smoke particle per frmae, too.
            cFX4Smoke.AddParticle(RandomPointOnSphere(10f) + heightVec, Vector3.Zero);
        }
        /// <summary>
        /// Updates the emitter, creating the appropriate number of particles
        /// in the appropriate positions.
        /// </summary>
        public void Update(GameTime gameTime, Vector3 newPosition)
        {
            if (gameTime == null)
            {
                throw new ArgumentNullException("gameTime");
            }

            // Work out how much time has passed since the previous update.
            float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds;

            if (elapsedTime > 0)
            {
                // Work out how fast we are moving.
                Vector3 velocity = (newPosition - previousPosition) / elapsedTime;

                // If we had any time left over that we didn't use during the
                // previous update, add that to the current elapsed time.
                float timeToSpend = timeLeftOver + elapsedTime;

                // Counter for looping over the time interval.
                float currentTime = -timeLeftOver;

                // Create particles as long as we have a big enough time interval.
                while (timeToSpend > timeBetweenParticles)
                {
                    currentTime += timeBetweenParticles;
                    timeToSpend -= timeBetweenParticles;

                    // Work out the optimal position for this particle. This will produce
                    // evenly spaced particles regardless of the object speed, particle
                    // creation frequency, or game update rate.
                    float mu = currentTime / elapsedTime;

                    Vector3 position = Vector3.Lerp(previousPosition, newPosition, mu);

                    // Create the particle.
                    particleSystem.AddParticle(position, velocity);
                }

                // Store any time we didn't use, so it can be part of the next update.
                timeLeftOver = timeToSpend;
            }

            previousPosition = newPosition;
        }
Example #5
0
 /// <summary>
 /// Helper for updating the smoke plume effect.
 /// </summary>
 void UpdateSmokePlume()
 {
     // This is trivial: we just create one new smoke particle per frame.
     smokePlumeParticles.AddParticle(Vector3.Zero, Vector3.Zero);
 }