コード例 #1
0
        private ExplosionParticle[,] GetExplosionParticles()
        {
            int sizeX         = (int)Target.Width / (int)ParticleSize;
            int sizeY         = (int)Target.Height / (int)ParticleSize;
            int shapesToSpawn = sizeX * sizeY;

            if (Target.Model is Shape)
            {
                Shape targetModel = Target.Model as Shape;
                Queue <ExplosionParticle> objects = Game.ExplosionParticlePool.Retrieve(Target.Model.GetType(), shapesToSpawn);
                ExplosionParticle[,] particles = new ExplosionParticle[sizeX, sizeY];
                for (int x = 0; x < sizeX; x++)
                {
                    for (int y = 0; y < sizeY; y++)
                    {
                        particles[x, y]                      = objects.Dequeue();
                        particles[x, y].Speed                = ParticleSpeed;
                        particles[x, y].SpinRate             = this.SpinRate;
                        particles[x, y].FadeOut              = this.FadeOut;
                        particles[x, y].Width                = ParticleSize;
                        particles[x, y].Height               = ParticleSize;
                        particles[x, y].Fill                 = targetModel.Fill;
                        particles[x, y].TargetDirection      = GameHelper.GetDirection(Game.Rand);
                        particles[x, y].LifeTimeMilliseconds = TimeSpanMilliseconds;
                    }
                }
                return(particles);
            }
            return(null);
        }
コード例 #2
0
ファイル: ParticlePool.cs プロジェクト: jenshamren/ShapeTD
        private Queue <ExplosionParticle> GetExplosionParticles(Type particleType, int particlesPerType)
        {
            Queue <ExplosionParticle> particles = new Queue <ExplosionParticle>();

            if (particleType == typeof(Rectangle))
            {
                for (int i = 0; i < particlesPerType; i++)
                {
                    ExplosionParticle particle = new ExplosionParticle(game, (Rectangle)GameHelper.Clone(game.GameObjectModels["rectangleExplosionParticle"]));
                    particles.Enqueue(particle);
                    particle.Model.Visibility = System.Windows.Visibility.Hidden;
                    game.PlayArea.Children.Add(particle.Model);
                }
            }
            if (particleType == typeof(Ellipse))
            {
                for (int i = 0; i < particlesPerType; i++)
                {
                    ExplosionParticle particle = new ExplosionParticle(game, (Ellipse)GameHelper.Clone(game.GameObjectModels["ellipseExplosionParticle"]));
                    particles.Enqueue(particle);
                    particle.Model.Visibility = System.Windows.Visibility.Hidden;
                    game.PlayArea.Children.Add(particle.Model);
                }
            }
            return(particles);
        }
コード例 #3
0
ファイル: ParticlePool.cs プロジェクト: jenshamren/ShapeTD
 public void Insert(ExplosionParticle particle)
 {
     particle.Reset();
     game.CancelUpdate(particle);
     if (particle.Model.GetType() == typeof(Rectangle))
     {
         rectangles.Enqueue(particle);
     }
     else if (particle.Model.GetType() == typeof(Ellipse))
     {
         ellipses.Enqueue(particle);
     }
 }
コード例 #4
0
ファイル: ParticlePool.cs プロジェクト: jenshamren/ShapeTD
        public Queue <ExplosionParticle> Retrieve(Type particleType, int amount)
        {
            Queue <ExplosionParticle> particles = new Queue <ExplosionParticle>();

            if (particleType == typeof(Rectangle))
            {
                for (int i = 0; i < amount; i++)
                {
                    ExplosionParticle particle = rectangles.Dequeue();
                    particles.Enqueue(particle);
                }
            }
            else if (particleType == typeof(Ellipse))
            {
                for (int i = 0; i < amount; i++)
                {
                    ExplosionParticle particle = ellipses.Dequeue();
                    particles.Enqueue(particle);
                }
            }
            return(particles);
        }