internal void SetType(ParticleType type) { Type = type; Scale = Type.ScaleModifier.Random; Angle = Type.AngleModifier.Random; Alpha = Type.AlphaModifier.Random; LifeMax = (int)Math.Round(Type.realLife.Random); Life = 0; LifePercent = 0; if (Type.Mode == ParticleType.FrameMode.Random) Frame = (int)Calc.Random.Next(Type.Sprite.Length); else Frame = 0; if (Type.BlendWithTime) Color = Type.Blend[0]; else Color = Calc.Random.Choose(Type.Blend); Velocity = new Angle(Type.Direction.Random, true).ToVector(Type.Speed.Random); DrawScale = new Vector2(Type.ScaleX.Min, Type.ScaleY.Min) * Type.Size.Min * Scale; DrawAngle = new Angle(Type.Angle.Min + Angle, true); }
/// <summary> /// Adds a particle to the system within a given radius. /// </summary> /// <param name="x">X center of the circle.</param> /// <param name="y">Y center of the circle.</param> /// <param name="radius">Radius of the circle.</param> /// <param name="type">The type of particle to add.</param> /// <param name="amount">The amount of particles to add.</param> public void AddParticleCircle(float x, float y, float radius, ParticleType type, int amount = 1) { Vector2 vector = new Vector2(); for (int i = 0; i < amount; ++i) { vector = Calc.Random.NextAngle().ToVector(Calc.Random.NextFloat(radius)); AddParticle(x + vector.X, y + vector.Y, type); } }
public ParticleType SetStep(ParticleType type, int numParticles = 1, float chance = 1.0f) { StepParticle = type; StepParticleAmount = numParticles; StepParticleChance = chance; return this; }
public ParticleType SetDeath(ParticleType type, int numParticles = 1, float chance = 1.0f) { DeathParticle = type; DeathParticleAmount = numParticles; DeathParticleChance = chance; return this; }
public ParticleRecord(string name, string subtexture, SpriteRecord record) { TextureName = name; SubtextureName = subtexture; Record = record; Type = new ParticleType(); }
/// <summary> /// Adds a particle to the system. /// </summary> /// <param name="x">The x position to add the particle at.</param> /// <param name="y">The y position to add the particle at.</param> /// <param name="type">The type of particle to add.</param> /// <param name="amount">The amount of particles to add.</param> public void AddParticle(float x, float y, ParticleType type, int amount = 1) { for(int i = 0; i < amount; ++i) AddParticle(x, y, type); }
private void AddParticle(float x, float y, ParticleType type) { while (ParticlesActive >= MaxParticles) RemoveParticle(0); Particle particle = particles[ParticlesActive++]; particle.SetType(type); particle.Position.X = x; particle.Position.Y = y; }