public void mediumMissileExplosion(Vector3 position, Vector3 velocity) { //explosion effect for (int i = 0; i < 35; i++) { mediumMissileParticles.AddParticle(position, velocity); } //smoke for after for (int i = 0; i < 5; i++) { smallExplosionSmokeParticles.AddParticle(position, velocity); } }
//update fire effect public void UpdateFire() { const int fireParticlePerFrame = 20; //create a number of fire particles, randomly around circle for (int i = 0; i < fireParticlePerFrame; i++) { fireParticles.AddParticle(RandomPointOnCircle(), Vector3.Zero); } //create one smoke particle per frame //smokePlumeParticles.AddParticle(RandomPointOnCircle(), Vector3.Zero); }
public void smallBulletExplosion(Vector3 position, Vector3 velocity) { //explosion effect for (int i = 0; i < 30; i++) { smallExplosionParticles.AddParticle(position, velocity); } //smoke for after for (int i = 0; i < 5; i++) { smallExplosionSmokeParticles.AddParticle(position, velocity); } }
public void ObjectDestroyedExplosion(Vector3 position, Vector3 velocity) { //explosion effect for (int i = 0; i < 35; i++) { explosionParticles.AddParticle(position, velocity); } //smoke for after for (int i = 0; i < 5; i++) { explosionSmokeParticles.AddParticle(position, velocity); } }
/// <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; }