2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
8 namespace SuperPolarity
12 private Random random;
13 public Vector2 EmitterLocation { get; set; }
14 public Color Color; //TODO: Color list for random colors.
16 public int TTLRandomFactor;
17 public int ScatterFactor;
18 public int ParticleCount;
19 public float StretchFactor;
20 private List<Particle> particles;
21 private List<Texture2D> textures;
23 public ParticleEngine(List<Texture2D> textures, Vector2 location)
25 EmitterLocation = location;
26 this.textures = textures;
27 this.particles = new List<Particle>();
28 random = new Random();
35 private Particle GenerateNewParticle()
37 Texture2D texture = textures[random.Next(textures.Count)];
38 Vector2 position = EmitterLocation;
39 Vector2 velocity = new Vector2(
40 1f * (float)(random.NextDouble() * 2 - 1),
41 1f * (float)(random.NextDouble() * 2 - 1));
44 float angularVelocity = 0.1f * (float)(random.NextDouble() * 2 - 1);
46 float size = (float)random.NextDouble() * StretchFactor;
48 position.X += random.Next(-ScatterFactor, ScatterFactor);
49 position.Y += random.Next(-ScatterFactor, ScatterFactor);
51 int ttl = TTL + random.Next(TTLRandomFactor);
53 return new Particle(texture, position, velocity, angle, angularVelocity, color, size, ttl);
60 for (int i = 0; i < total; i++)
62 particles.Add(GenerateNewParticle());
65 for (int particle = 0; particle < particles.Count; particle++)
67 particles[particle].Update();
68 if (particles[particle].TTL <= 0)
70 particles.RemoveAt(particle);
76 public void Draw(SpriteBatch spriteBatch)
78 //spriteBatch.Begin();
79 for (int index = 0; index < particles.Count; index++)
81 particles[index].Draw(spriteBatch);