Пример #1
0
        void SetHexString()
        {
            string hexA = Alpha.ToString("X");
            string hexR = ColorR.ToString("X");
            string hexG = ColorG.ToString("X");
            string hexB = ColorB.ToString("X");

            // .ToString("X") returns "0" for a 0 value, we want full hex pairs, so replace with "00"
            if (hexA == "0")
            {
                hexA = "00";
            }
            if (hexR == "0")
            {
                hexR = "00";
            }
            if (hexG == "0")
            {
                hexG = "00";
            }
            if (hexB == "0")
            {
                hexB = "00";
            }

            _hexColor = hexA + hexR + hexG + hexB;
        }
Пример #2
0
        private Particle GenerateParticle(int index)
        {
            float speedMultiplier    = 1 + random.NextFloat(-SpeedDeviation, SpeedDeviation);
            float rotationMultiplier = 1 + random.NextFloat(-RotationDeviation, RotationDeviation);
            float scaleMultiplier    = 1 + random.NextFloat(-ScaleDeviation, ScaleDeviation);

            return(new Particle(Texture, EmitterLocations[index] + new Vector2(Global.rand.NextFloat(0, 0.99f), Global.rand.NextFloat(0, 0.99f)),
                                Utils.Vector2FromSpeedAndDirection(Speed.Evaluate(0) * speedMultiplier, random.NextFloat(MinDirection, MaxDirection)),
                                speedMultiplier, Rotation.Evaluate(0) * rotationMultiplier, rotationMultiplier,
                                new Color(ColorR.Evaluate(0), ColorG.Evaluate(0), ColorB.Evaluate(0), ColorA.Evaluate(0)),
                                Scale.Evaluate(0), scaleMultiplier, random.NextFloat(MinLifetime, MaxLifetime), HurtsPlayer, DamageRatio));
        }
Пример #3
0
        public void Update(GameTime gameTime, PlayState map, bool emitParticles)
        {
            foreach (Particle particle in particles)
            {
                particle.Update(gameTime, map);
                float age = particle.Age / particle.Lifetime;

                Vector2 direction = particle.Velocity;
                if (direction != Vector2.Zero)
                {
                    direction.Normalize();
                }
                particle.Velocity = direction * Speed.Evaluate(age) * particle.SpeedMultiplier;
                particle.Rotation = Rotation.Evaluate(age) * particle.RotationMultiplier;
                particle.Scale    = Scale.Evaluate(age) * particle.ScaleMultiplier;

                particle.Color = new Color(ColorR.Evaluate(age), ColorG.Evaluate(age), ColorB.Evaluate(age), ColorA.Evaluate(age));
            }

            for (int i = 0; i < particles.Count; i++)
            {
                if (particles[i].Age >= particles[i].Lifetime)
                {
                    particles.RemoveAt(i);
                    i--;
                }
            }

            if (emitParticles)
            {
                for (int j = EmitterLocations.Count - 1; j >= 0; j--)
                {
                    float emission = (float)gameTime.ElapsedGameTime.TotalSeconds * EmissionRate;
                    emissionError += emission - (float)Math.Floor(emission);
                    emission      -= emission - (float)Math.Floor(emission);
                    emission      += (float)Math.Floor(emissionError);
                    emissionError -= (float)Math.Floor(emissionError);
                    for (int i = 0; i < emission; i++)
                    {
                        particles.Add(GenerateParticle(j));
                    }
                }
            }

            foreach (IParticleManipulator manipulator in Manipulators)
            {
                foreach (Particle particle in particles)
                {
                    manipulator.ManipulateParticle(particle);
                }
            }
        }
Пример #4
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (X != 0F)
            {
                hash ^= X.GetHashCode();
            }
            if (Y != 0F)
            {
                hash ^= Y.GetHashCode();
            }
            if (Vx != 0F)
            {
                hash ^= Vx.GetHashCode();
            }
            if (Vy != 0F)
            {
                hash ^= Vy.GetHashCode();
            }
            if (Rotation != 0F)
            {
                hash ^= Rotation.GetHashCode();
            }
            if (Omega != 0F)
            {
                hash ^= Omega.GetHashCode();
            }
            if (InitLife != 0F)
            {
                hash ^= InitLife.GetHashCode();
            }
            if (Life != 0F)
            {
                hash ^= Life.GetHashCode();
            }
            if (Scale != 0F)
            {
                hash ^= Scale.GetHashCode();
            }
            if (Alpha != 0F)
            {
                hash ^= Alpha.GetHashCode();
            }
            if (Mass != 0F)
            {
                hash ^= Mass.GetHashCode();
            }
            if (IsDead != false)
            {
                hash ^= IsDead.GetHashCode();
            }
            if (ColorR != 0F)
            {
                hash ^= ColorR.GetHashCode();
            }
            if (ColorG != 0F)
            {
                hash ^= ColorG.GetHashCode();
            }
            if (ColorB != 0F)
            {
                hash ^= ColorB.GetHashCode();
            }
            if (CurrentAnimationFrame != 0)
            {
                hash ^= CurrentAnimationFrame.GetHashCode();
            }
            return(hash);
        }