1 | using System; |
---|
2 | using System.Collections.Generic; |
---|
3 | using System.Linq; |
---|
4 | using Microsoft.Xna.Framework; |
---|
5 | using Microsoft.Xna.Framework.Audio; |
---|
6 | using Microsoft.Xna.Framework.Content; |
---|
7 | using Microsoft.Xna.Framework.GamerServices; |
---|
8 | using Microsoft.Xna.Framework.Graphics; |
---|
9 | using Microsoft.Xna.Framework.Input; |
---|
10 | using Microsoft.Xna.Framework.Media; |
---|
11 | using Microsoft.Xna.Framework.Net; |
---|
12 | using Microsoft.Xna.Framework.Storage; |
---|
13 | |
---|
14 | namespace Effects |
---|
15 | { |
---|
16 | public abstract class ParticleSystem : DrawableGameComponent |
---|
17 | { |
---|
18 | private Game game; |
---|
19 | |
---|
20 | private Particle[] particles; |
---|
21 | |
---|
22 | #region Subclass variables |
---|
23 | protected Vector2 position; |
---|
24 | |
---|
25 | protected String textureName; |
---|
26 | |
---|
27 | protected String innerTextureName; |
---|
28 | protected String outerTextureName; |
---|
29 | |
---|
30 | protected float minScale; |
---|
31 | protected float maxScale; |
---|
32 | |
---|
33 | protected float rotation; |
---|
34 | |
---|
35 | protected Vector2 origin; |
---|
36 | |
---|
37 | protected Vector2 minVelocity; |
---|
38 | protected Vector2 maxVelocity; |
---|
39 | |
---|
40 | protected float minLifetime; |
---|
41 | protected float maxLifetime; |
---|
42 | |
---|
43 | #endregion |
---|
44 | |
---|
45 | private enum TextureType |
---|
46 | { |
---|
47 | Single, |
---|
48 | Dual |
---|
49 | }; |
---|
50 | |
---|
51 | private TextureType textureType; |
---|
52 | |
---|
53 | private Texture2D texture, innerTexture, outerTexture; |
---|
54 | |
---|
55 | private int maxAmountOfParticles; |
---|
56 | public int MaxAmountOfParticles |
---|
57 | { |
---|
58 | get { return maxAmountOfParticles; } |
---|
59 | set { maxAmountOfParticles = value; } |
---|
60 | } |
---|
61 | |
---|
62 | public ParticleSystem(Game game, Vector2 position, String textureName) |
---|
63 | : base(game) |
---|
64 | { |
---|
65 | textureType = TextureType.Single; |
---|
66 | this.game = game; |
---|
67 | } |
---|
68 | |
---|
69 | public ParticleSystem(Game game, Vector2 position, String innerTextureName, String outerTextureName) |
---|
70 | : base(game) |
---|
71 | { |
---|
72 | textureType = TextureType.Dual; |
---|
73 | this.game = game; |
---|
74 | } |
---|
75 | |
---|
76 | protected abstract void InitializeParticles(); |
---|
77 | |
---|
78 | protected override void LoadContent() |
---|
79 | { |
---|
80 | if (textureType == TextureType.Single) |
---|
81 | { |
---|
82 | texture = game.Content.Load<Texture2D>(textureName.ToString()); |
---|
83 | } |
---|
84 | if (textureType == TextureType.Dual) |
---|
85 | { |
---|
86 | innerTexture = game.Content.Load<Texture2D>(innerTextureName.ToString()); |
---|
87 | outerTexture = game.Content.Load<Texture2D>(outerTextureName.ToString()); |
---|
88 | } |
---|
89 | base.LoadContent(); |
---|
90 | } |
---|
91 | } |
---|
92 | } |
---|