123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- #region File Description
- //-----------------------------------------------------------------------------
- // SmokePlumeParticleSystem.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- #endregion
- #region Using Statements
- using System;
- using System.Collections.Generic;
- using System.Text;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- #endregion
- namespace ParticleSample
- {
- /// <summary>
- /// SmokePlumeParticleSystem is a specialization of ParticleSystem which sends up a
- /// plume of smoke. The smoke is blown to the right by the wind.
- /// </summary>
- public class SmokePlumeParticleSystem : ParticleSystem
- {
- public SmokePlumeParticleSystem(ParticleSampleGame game, int howManyEffects)
- : base(game,howManyEffects)
- {
- }
- /// <summary>
- /// Set up the constants that will give this particle system its behavior and
- /// properties.
- /// </summary>
- protected override void InitializeConstants()
- {
- textureFilename = "smoke";
- minInitialSpeed = 20;
- maxInitialSpeed = 100;
- // we don't want the particles to accelerate at all, aside from what we
- // do in our overriden InitializeParticle.
- minAcceleration = 0;
- maxAcceleration = 0;
- // long lifetime, this can be changed to create thinner or thicker smoke.
- // tweak minNumParticles and maxNumParticles to complement the effect.
- minLifetime = 5.0f;
- maxLifetime = 7.0f;
- minScale = .5f;
- maxScale = 1.0f;
- // we need to reduce the number of particles on Windows Phone in order to keep
- // a good framerate
- #if WINDOWS_PHONE
- minNumParticles = 3;
- maxNumParticles = 8;
- #else
- minNumParticles = 7;
- maxNumParticles = 15;
- #endif
- // rotate slowly, we want a fairly relaxed effect
- minRotationSpeed = -MathHelper.PiOver4 / 2.0f;
- maxRotationSpeed = MathHelper.PiOver4 / 2.0f;
- blendState = BlendState.AlphaBlend;
- DrawOrder = AlphaBlendDrawOrder;
- }
- /// <summary>
- /// PickRandomDirection is overriden so that we can make the particles always
- /// move have an initial velocity pointing up.
- /// </summary>
- /// <returns>a random direction which points basically up.</returns>
- protected override Vector2 PickRandomDirection()
- {
- // Point the particles somewhere between 80 and 100 degrees.
- // tweak this to make the smoke have more or less spread.
- float radians = ParticleSampleGame.RandomBetween(
- MathHelper.ToRadians(80), MathHelper.ToRadians(100));
- Vector2 direction = Vector2.Zero;
- // from the unit circle, cosine is the x coordinate and sine is the
- // y coordinate. We're negating y because on the screen increasing y moves
- // down the monitor.
- direction.X = (float)Math.Cos(radians);
- direction.Y = -(float)Math.Sin(radians);
- return direction;
- }
- /// <summary>
- /// InitializeParticle is overridden to add the appearance of wind.
- /// </summary>
- /// <param name="p">the particle to set up</param>
- /// <param name="where">where the particle should be placed</param>
- protected override void InitializeParticle(Particle p, Vector2 where)
- {
- base.InitializeParticle(p, where);
- // the base is mostly good, but we want to simulate a little bit of wind
- // heading to the right.
- p.Acceleration.X += ParticleSampleGame.RandomBetween(10, 50);
- }
- }
- }
|