diff options
| author | Ben Beltran <ben@nsovocal.com> | 2014-02-03 10:06:44 -0600 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2014-02-03 10:06:44 -0600 |
| commit | 4fc09567c557a1110180940cca40fd7144921026 (patch) | |
| tree | 5fb7b0b787b739a3f4a2785651c69219a8318ab0 /SuperPolarityMac/ParticleEngine.cs | |
| parent | 0cafec445af0a97d96feb1a1daefa1486142c73f (diff) | |
Removes spaces.
Diffstat (limited to 'SuperPolarityMac/ParticleEngine.cs')
| -rw-r--r-- | SuperPolarityMac/ParticleEngine.cs | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/SuperPolarityMac/ParticleEngine.cs b/SuperPolarityMac/ParticleEngine.cs new file mode 100644 index 0000000..51188ae --- /dev/null +++ b/SuperPolarityMac/ParticleEngine.cs @@ -0,0 +1,86 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; + +namespace SuperPolarity +{ + class ParticleEngine + { + private Random random; + public Vector2 EmitterLocation { get; set; } + public Color Color; //TODO: Color list for random colors. + public int TTL; + public int TTLRandomFactor; + public int ScatterFactor; + public int ParticleCount; + public float StretchFactor; + private List<Particle> particles; + private List<Texture2D> textures; + + public ParticleEngine(List<Texture2D> textures, Vector2 location) + { + EmitterLocation = location; + this.textures = textures; + this.particles = new List<Particle>(); + random = new Random(); + Color = Color.Red; + TTL = 20; + TTLRandomFactor = 40; + StretchFactor = 1; + } + + private Particle GenerateNewParticle() + { + Texture2D texture = textures[random.Next(textures.Count)]; + Vector2 position = EmitterLocation; + Vector2 velocity = new Vector2( + 1f * (float)(random.NextDouble() * 2 - 1), + 1f * (float)(random.NextDouble() * 2 - 1)); + + float angle = 0; + float angularVelocity = 0.1f * (float)(random.NextDouble() * 2 - 1); + Color color = Color; + float size = (float)random.NextDouble() * StretchFactor; + + position.X += random.Next(-ScatterFactor, ScatterFactor); + position.Y += random.Next(-ScatterFactor, ScatterFactor); + + int ttl = TTL + random.Next(TTLRandomFactor); + + return new Particle(texture, position, velocity, angle, angularVelocity, color, size, ttl); + } + + public void Update() + { + int total = 10; + + for (int i = 0; i < total; i++) + { + particles.Add(GenerateNewParticle()); + } + + for (int particle = 0; particle < particles.Count; particle++) + { + particles[particle].Update(); + if (particles[particle].TTL <= 0) + { + particles.RemoveAt(particle); + particle--; + } + } + } + + public void Draw(SpriteBatch spriteBatch) + { + //spriteBatch.Begin(); + for (int index = 0; index < particles.Count; index++) + { + particles[index].Draw(spriteBatch); + } + //spriteBatch.End(); + } + } +} |