/// <summary> /// Initializes a particle /// </summary> /// <param name="p"></param> /// <param name="where"></param> /// <param name="direction">set to null for a random direction for each particle</param> protected virtual void InitializeParticle(Particle p, Vector2 where, Vector2 direction) { if (direction == null) { direction = PickRandomDirection(); } // pick some random values for our particle float velocity = RandomNumberProvider.RandomBetween(minInitialSpeed, maxInitialSpeed); float acceleration = RandomNumberProvider.RandomBetween(minAcceleration, maxAcceleration); float lifetime = RandomNumberProvider.RandomBetween(minLifetime, maxLifetime); float scale = RandomNumberProvider.RandomBetween(minScale, maxScale); float rotationSpeed = RandomNumberProvider.RandomBetween(minRotationSpeed, maxRotationSpeed); // then initialize it with those random values. initialize will save those, // and make sure it is marked as active. p.Initialize( where, velocity * direction, acceleration * direction, lifetime, scale, rotationSpeed); }
public void Initialize(Vector2 position, Vector2 velocity, Vector2 acceleration, float lifetime, float scale, float rotationSpeed) { this.InitialPosition = position; this.Position = position; this.Velocity = velocity; this.InitialVelocity = velocity; this.Acceleration = acceleration; this.Lifetime = lifetime; this.Scale = scale; this.RotationSpeed = rotationSpeed; this.TimeSinceStart = 0.0f; this.Rotation = RandomNumberProvider.RandomBetween(0, MathHelper.TwoPi); }
protected virtual Vector2 PickRandomDirection() { float angle = RandomNumberProvider.RandomBetween(0, MathHelper.TwoPi); return(new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))); }