Ejemplo n.º 1
0
        /// <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 =
                CalcHelper.RandomBetween(minInitialSpeed, maxInitialSpeed);
            //_velocity = new Vector2(_velocity.X + vel, _velocity.Y + vel);
            float acceleration =
                CalcHelper.RandomBetween(minAcceleration, maxAcceleration);
            float lifetime =
                CalcHelper.RandomBetween(minLifetime, maxLifetime);
            float scale =
                CalcHelper.RandomBetween(minScale, maxScale);
            float rotationSpeed =
                CalcHelper.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);
        }