// initialize is called by ParticleSystem to set up the particle, and prepares // the particle for use. public void Initialize(Vector2 position, Vector2 velocity, Vector2 acceleration, float lifetime, float scale, float rotationSpeed) { // set the values to the requested values this.Position = position; this.Velocity = velocity; this.Acceleration = acceleration; this.Lifetime = lifetime; this.Scale = scale; this.RotationSpeed = rotationSpeed; // reset TimeSinceStart - we have to do this because particles will be // reused. this.TimeSinceStart = 0.0f; // set rotation to some random value between 0 and 360 degrees. this.Rotation = LaserBikes.RandomBetween(0, MathHelper.TwoPi); }
/// <summary> /// InitializeParticle randomizes some properties for a particle, then /// calls initialize on it. It can be overriden by subclasses if they /// want to modify the way particles are created. For example, /// SmokePlumeParticleSystem overrides this function make all particles /// accelerate to the right, simulating wind. /// </summary> /// <param name="p">the particle to initialize</param> /// <param name="where">the position on the screen that the particle should be /// </param> protected virtual void InitializeParticle(Particle p, Vector2 where) { // first, call PickRandomDirection to figure out which way the particle // will be moving. velocity and acceleration's values will come from this. Vector2 direction = PickRandomDirection(); // pick some random values for our particle float velocity = LaserBikes.RandomBetween(minInitialSpeed, maxInitialSpeed); float acceleration = LaserBikes.RandomBetween(minAcceleration, maxAcceleration); float lifetime = LaserBikes.RandomBetween(minLifetime, maxLifetime); float scale = LaserBikes.RandomBetween(minScale, maxScale); float rotationSpeed = LaserBikes.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); }
/// <summary> /// PickRandomDirection is used by InitializeParticles to decide which direction /// particles will move. The default implementation is a random vector in a /// circular pattern. /// </summary> protected virtual Vector2 PickRandomDirection() { float angle = LaserBikes.RandomBetween(0, MathHelper.TwoPi); return(new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))); }
/// <summary> /// Constructs a new ParticleSystem. /// </summary> /// <param name="game">The host for this particle system. The game keeps the /// content manager and sprite batch for us.</param> /// <param name="howManyEffects">the maximum number of particle effects that /// are expected on screen at once.</param> /// <remarks>it is tempting to set the value of howManyEffects very high. /// However, this value should be set to the minimum possible, because /// it has a large impact on the amount of memory required, and slows down the /// Update and Draw functions.</remarks> protected ParticleSystem(LaserBikes game, int howManyEffects) : base(game) { this.game = game; this.howManyEffects = howManyEffects; }
public ExplosionParticleSystem(LaserBikes game, int howManyEffects) : base(game, howManyEffects) { }
static void Main() { using (var game = new LaserBikes()) game.Run(); }