Changeset 831
- Timestamp:
- 2010-06-14 23:49:26 (13 years ago)
- Location:
- 2010/23/sijoseha/alpha/Effects
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
2010/23/sijoseha/alpha/Effects/Explosion.cs
r822 r831 17 17 { 18 18 19 public Explosion(ParticleGame game, Vector2 position , String textureName)20 : base(game, position , textureName)19 public Explosion(ParticleGame game, Vector2 position) 20 : base(game, position) 21 21 { 22 22 … … 25 25 protected override void InitializeParticles() 26 26 { 27 27 textureName = "Glow"; 28 29 30 textureType = TextureType.Single; 31 32 minLifetime = 0.5f; 33 maxLifetime = 1.0f; 34 35 minScale = 0.5f; 36 maxScale = 1.0f; 37 38 minVelocity = 5f; 39 maxVelocity = 10f; 40 41 rotation = 0.0f; 28 42 } 29 43 } -
2010/23/sijoseha/alpha/Effects/Particle.cs
r819 r831 14 14 namespace Effects 15 15 { 16 class Particle16 public class Particle 17 17 { 18 18 … … 84 84 #endregion 85 85 86 public void Initialize( Texture2D texture,Vector2 position, float scale, float rotation, Vector2 velocity, float lifetime)86 public void Initialize(Vector2 position, float scale, float rotation, Vector2 velocity, float lifetime) 87 87 { 88 88 this.alive = true; 89 this.texture = texture;90 89 this.position = position; 91 90 this.scale = scale; -
2010/23/sijoseha/alpha/Effects/ParticleGame.cs
r822 r831 26 26 } 27 27 28 29 Particle[] particles;30 28 Random random = new Random(); 31 const int amountOfParticles = 15;32 29 33 30 KeyboardState previousKeyboardState = Keyboard.GetState(); 31 32 Explosion explosion; 34 33 35 34 public ParticleGame() 36 35 { 37 36 graphics = new GraphicsDeviceManager(this); 37 38 explosion = new Explosion(this, Vector2.Zero); 39 38 40 Content.RootDirectory = "Content"; 39 41 } … … 58 60 protected override void LoadContent() 59 61 { 60 particles = new Particle[amountOfParticles];61 62 Texture2D glowTexture = Content.Load<Texture2D>("Glow"); 62 63 Texture2D glowTexture2 = Content.Load<Texture2D>("Glow2"); 63 64 // Create a new SpriteBatch, which can be used to draw textures. 64 65 spriteBatch = new SpriteBatch(GraphicsDevice); 65 for (int i = 0; i < particles.Length; i++)66 {67 particles[i] = new Particle(this, glowTexture, glowTexture2, new Vector2(68 (float)random.NextDouble() * graphics.GraphicsDevice.Viewport.Width,69 (float)random.NextDouble() * graphics.GraphicsDevice.Viewport.Height), 2.0f);70 particles[i].Scale = (float)random.NextDouble();//0.2f + (float)random.NextDouble() * 0.8f;71 particles[i].Velocity = new Vector2(72 (float)random.NextDouble() * 5 - 2.5f,73 (float)random.NextDouble() * 5 - 2.5f);74 75 }76 66 // TODO: use this.Content to load your game content here 77 67 } … … 94 84 { 95 85 float dt = (float)gameTime.ElapsedGameTime.TotalSeconds; 96 KeyboardState keyboardState = Keyboard.GetState();97 MouseState mouseState = Mouse.GetState();98 // Allows the game to exit99 if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)100 this.Exit();101 for (int i = 0; i < particles.Length; i++)102 {103 if (particles[i].Alive)104 {105 particles[i].CurrentTime += dt;106 particles[i].Scale = 1.0f - (particles[i].Lifetime * particles[i].CurrentTime);107 particles[i].Position += particles[i].Velocity;108 if (particles[i].CurrentTime > particles[i].Lifetime)109 {110 particles[i].Alive = false;111 }112 }113 if (!particles[i].Alive)114 {115 particles[i].Alive = true;116 particles[i].Lifetime = 2.0f;117 particles[i].CurrentTime = 0.0f;118 particles[i].Scale = 1.0f;119 particles[i].Position = new Vector2(120 (float)mouseState.X,121 (float)mouseState.Y);122 particles[i].Velocity = new Vector2(123 (float)random.NextDouble() * 5 - 2.5f,124 (float)random.NextDouble() * 5 - 2.5f);125 //particles[i].Position = new Vector2(126 //(float)random.NextDouble() * graphics.GraphicsDevice.Viewport.Width,127 //(float)random.NextDouble() * graphics.GraphicsDevice.Viewport.Height);128 }129 }130 131 // TODO: Add your update logic here132 133 previousKeyboardState = keyboardState;134 86 base.Update(gameTime); 135 87 } … … 143 95 GraphicsDevice.Clear(Color.Black); 144 96 // TODO: Add your drawing code here 145 146 97 base.Draw(gameTime); 147 98 } -
2010/23/sijoseha/alpha/Effects/ParticleSystem.cs
r822 r831 38 38 protected Vector2 origin; 39 39 40 protected Vector2minVelocity;41 protected Vector2maxVelocity;40 protected float minVelocity; 41 protected float maxVelocity; 42 42 43 43 protected float minLifetime; … … 46 46 #endregion 47 47 48 pr ivateenum TextureType48 protected enum TextureType 49 49 { 50 50 Single, … … 52 52 }; 53 53 54 pr ivateTextureType textureType;54 protected TextureType textureType; 55 55 56 56 private Texture2D texture, innerTexture, outerTexture; … … 64 64 } 65 65 66 public ParticleSystem(ParticleGame game, Vector2 position , String textureName)66 public ParticleSystem(ParticleGame game, Vector2 position) 67 67 : base(game) 68 68 { 69 textureType = TextureType.Single;70 this.game = game;71 }72 73 public ParticleSystem(ParticleGame game, Vector2 position, String innerTextureName, String outerTextureName)74 : base(game)75 {76 textureType = TextureType.Dual;77 69 this.game = game; 78 70 } … … 80 72 protected abstract void InitializeParticles(); 81 73 74 protected virtual void InitializeParticle(Particle p, Vector2 position) 75 { 76 Vector2 direction = new Vector2(-100, 0); 77 78 float scale = 1.0f; 79 float rotation = 0.0f; 80 float velocity = 1.0f; 81 float lifetime = 1.0f; 82 83 p.Initialize(position, scale, rotation, velocity * direction, lifetime); 84 } 85 82 86 public override void Initialize() 83 87 { 88 particles = new Particle[maxAmountOfParticles]; 84 89 for (int i = 0; i < maxAmountOfParticles; i++) 85 90 { … … 91 96 protected override void LoadContent() 92 97 { 93 particles = new Particle[maxAmountOfParticles];94 98 if (textureType == TextureType.Single) 95 99 { … … 111 115 public override void Update(GameTime gameTime) 112 116 { 117 float time = (float)gameTime.ElapsedGameTime.TotalSeconds; 118 119 foreach (Particle p in particles) 120 { 121 if (p.Alive) 122 { 123 p.Update(time); 124 } 125 } 113 126 114 127 base.Update(gameTime);
Note: See TracChangeset
for help on using the changeset viewer.