예제 #1
0
        public void Update(GameTime gameTime)
        {
            float now = (float)gameTime.TotalGameTime.TotalMilliseconds;

            for (int i = particleList.Count - 1; i >= 0; i--)
            {
                ParticleData particle  = particleList[i];
                float        timeAlive = now - particle.BirthTime;

                if (timeAlive > particle.MaxAge)
                {
                    particleList.RemoveAt(i);
                }
                else
                {
                    float relAge = timeAlive / particle.MaxAge;
                    particle.Position = 0.5f * particle.Accelaration * relAge * relAge + particle.Direction * relAge + particle.OrginalPosition;
                    float invAge = 1.0f - relAge;
                    particle.ModColor = new Color(new Vector4(invAge, invAge, invAge, invAge));
                    Vector2 positionFromCenter = particle.Position - particle.OrginalPosition;
                    float   distance           = positionFromCenter.Length();
                    particle.Scaling = (50.0f + distance) / 200.0f;
                    particleList[i]  = particle;
                }
            }
        }
예제 #2
0
 public void Draw(SpriteBatch spriteBatch)
 {
     spriteBatch.End();
     spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.Additive);
     for (int i = 0; i < particleList.Count; i++)
     {
         ParticleData particle = particleList[i];
         spriteBatch.Draw(explosionTexture, particle.Position, null, particle.ModColor, i, new Vector2(256, 256), particle.Scaling, SpriteEffects.None, 1);
     }
     spriteBatch.End();
     spriteBatch.Begin();
 }
예제 #3
0
        private void AddExplosionParticle(Vector2 explosionPos, float explosionSize, float maxAge, GameTime gameTime)
        {
            ParticleData particle = new ParticleData();

            particle.OrginalPosition = explosionPos;
            particle.Position        = particle.OrginalPosition;

            particle.BirthTime = (float)gameTime.TotalGameTime.TotalMilliseconds;
            particle.MaxAge    = maxAge;
            particle.Scaling   = 0.25f;
            particle.ModColor  = Color.White;

            float   particleDistance = (float)randomizer.NextDouble() * explosionSize;
            Vector2 displacement     = new Vector2(particleDistance, 0);
            float   angle            = MathHelper.ToRadians(randomizer.Next(360));

            displacement = Vector2.Transform(displacement, Matrix.CreateRotationZ(angle));

            particle.Direction    = displacement * 2.0f;
            particle.Accelaration = -particle.Direction;

            particleList.Add(particle);
        }