Exemplo n.º 1
0
        protected override void InitializeParticle(Particle p, Vector2 where)
        {
            base.InitializeParticle(p, where);

            // the base is mostly good, but we want to simulate a little bit of wind
            // heading to the right.
            p.Acceleration.X += MathHelp.RandomBetween(10, 50);
        }
Exemplo n.º 2
0
        protected override Vector2 PickRandomDirection()
        {
            // Point the particles somewhere between 80 and 100 degrees.
            // tweak this to make the smoke have more or less spread.
            float radians = MathHelp.RandomBetween(
                MathHelper.ToRadians(80), MathHelper.ToRadians(100));

            Vector2 direction = Vector2.Zero;

            // from the unit circle, cosine is the x coordinate and sine is the
            // y coordinate. We're negating y because on the screen increasing y moves
            // down the monitor.
            // direction.X = (float)Math.Cos(radians);
            direction.Y = Direction;
            return(direction);
        }
Exemplo n.º 3
0
        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 = new Vector2(1, -1);

            // pick some random values for our particle
            float velocity =
                MathHelp.RandomBetween(minInitialSpeed, maxInitialSpeed);
            float acceleration =
                MathHelp.RandomBetween(minAcceleration, maxAcceleration);
            float lifetime =
                MathHelp.RandomBetween(minLifetime, maxLifetime);
            float scale =
                MathHelp.RandomBetween(minScale, maxScale);
            float rotationSpeed =
                MathHelp.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);
        }
Exemplo n.º 4
0
        /// <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 = MathHelp.RandomBetween(0, MathHelper.TwoPi);

            return(new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle)));
        }