diff options
| author | Ben Beltran <ben@nsovocal.com> | 2013-11-10 22:11:08 -0600 |
|---|---|---|
| committer | Ben Beltran <ben@nsovocal.com> | 2013-11-10 22:11:08 -0600 |
| commit | 95d7601b7742ed560a9d8e00269217f62fc7ce32 (patch) | |
| tree | 66b3ac90c47c202c017e78d347bcd4c33121a28c /Super Polarity/ParticleEngine.cs | |
| parent | 9899ae5d21c559b98386be48c5a80e63db10552d (diff) | |
Chubas's House happened.
Diffstat (limited to 'Super Polarity/ParticleEngine.cs')
| -rw-r--r-- | Super Polarity/ParticleEngine.cs | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Super Polarity/ParticleEngine.cs b/Super Polarity/ParticleEngine.cs new file mode 100644 index 0000000..5cf6bdb --- /dev/null +++ b/Super Polarity/ParticleEngine.cs @@ -0,0 +1,75 @@ +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; } + 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(); + } + + 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 = new Color( + (float)random.NextDouble(), + (float)random.NextDouble(), + (float)random.NextDouble()); + float size = (float)random.NextDouble(); + + int ttl = 20 + random.Next(40); + + 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(); + } + } +} |