예제 #1
0
        public static void UpdateParticles(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.ModColour = 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 static void DrawExplosion(Texture2D aTexture)
 {
     for (int i = 0; i < particleList.Count; i++)
     {
         ParticleData particle = particleList[i];
         spriteBatch.Draw(aTexture, particle.Position, null, particle.ModColour, i,
                          new Vector2(256, 256), particle.Scaling,
                          SpriteEffects.None, 1);
     }
 }
예제 #3
0
        public static 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.ModColour = Color.White;

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

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

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

            particleList.Add(particle);
        }