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)); }
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); } } }
public Ball Evaluate(int cacheGeneration = 0) { if (cacheGeneration == 0) { cacheGeneration = Expression.NextAutoIncrementId; } return(new Ball() { Position = Position.Evaluate(cacheGeneration), Speed = Speed.Evaluate(cacheGeneration), AngularSpeed = AngularSpeed.Evaluate(cacheGeneration) }); }