コード例 #1
0
ファイル: ParticleAffector.cs プロジェクト: Yozer/NanoWar
        public void ApplyAffector(Particle currentParticle, TimeSpan elapsedTime, TimeSpan totalTime)
        {
            if (currentParticle.Color.A == 254)
            {
                if (MathHelper.DistanceBetweenTwoPints(currentParticle.Position, _origin) <= _radius)
                {
                    currentParticle.Velocity = new Vector2f(0, 0);
                    currentParticle.Color = new Color(0, 0, 0, 0);
                }
            }
            else if (MathHelper.DistanceBetweenTwoPints(currentParticle.Position, _explosionOrigin) >= _maxDistance)
            {
                currentParticle.Color = new Color(
                    currentParticle.Color.R,
                    currentParticle.Color.G,
                    currentParticle.Color.B,
                    254);
                currentParticle.Velocity = 350
                                           * MathHelper.NormalizeVector(
                                               new Vector2f(
                                                 _origin.X - currentParticle.Position.X,
                                                 _origin.Y - currentParticle.Position.Y));
            }
            else if (currentParticle.Color.A != 0)
            {
                var speed = (float)Math.Log(totalTime.TotalSeconds, 5.5f);
                if (float.IsInfinity(speed) || float.IsNaN(speed))
                {
                    return;
                }

                currentParticle.Velocity += MathHelper.NormalizeVector(currentParticle.Velocity) * speed;
            }
        }
コード例 #2
0
ファイル: ParticleEmitter.cs プロジェクト: Yozer/NanoWar
        public override void EmitParticles(ParticleSystem particleSystem, TimeSpan deltaTime)
        {
            for (var i = 0;
                 i
                 < (deltaTime == TimeSpan.Zero
                        ? int.MaxValue
                        : deltaTime.TotalMilliseconds / _interval.TotalMilliseconds) && _particleCount > 0;
                 i++, _particleCount--)
            {
                var velocity = new PolarVector(
                    _rndgenerator.Next(7000, 9000) / 100f,
                    _rndgenerator.Next((int)(_angle - 85f), (int)(_angle + 85f)));

                var particle = new Particle(TimeSpan.Zero) { Position = _position, Velocity = velocity, Color = _color };
                EmitParticle(particleSystem, particle);
            }
        }
コード例 #3
0
ファイル: EmitterBase.cs プロジェクト: Yozer/NanoWar
 protected void EmitParticle(ParticleSystem particleSystem, Particle particle)
 {
     particleSystem.AddParticle(particle);
 }