Exemplo n.º 1
0
        /// <summary>
        /// Initialize a new particle using the values in this system.
        /// </summary>
        /// <param name="particle">The particle to be initialized.</param>
        private void InitializeParticle(Particle particle)
        {
            // safety-check the parameter
            if (particle == null)
            {
                throw new ArgumentNullException("particle");
            }

            // set the time remaining on the new particle
            particle.TimeRemaining = RandomMath.RandomBetween(durationMinimum,
                                                              durationMaximum);

            // generate a random direction
            Vector2 direction = RandomMath.RandomDirection(releaseAngleMinimum,
                                                           releaseAngleMaximum);

            // set the graphics data on the new particle
            particle.Position = position + direction *
                                RandomMath.RandomBetween(releaseDistanceMinimum,
                                                         releaseDistanceMaximum);
            particle.Velocity = direction * RandomMath.RandomBetween(velocityMinimum,
                                                                     velocityMaximum);
            if (particle.Velocity.LengthSquared() > 0f)
            {
                particle.Acceleration = direction *
                                        RandomMath.RandomBetween(accelerationMinimum, accelerationMaximum);
            }
            else
            {
                particle.Acceleration = Vector2.Zero;
            }
            particle.Rotation = RandomMath.RandomBetween(0f, MathHelper.TwoPi);
            particle.Scale    = RandomMath.RandomBetween(scaleMinimum, scaleMaximum);
            particle.Opacity  = RandomMath.RandomBetween(opacityMinimum, opacityMaximum);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Construct a new asteroid.
        /// </summary>
        /// <param name="world">The world that this asteroid belongs to.</param>
        /// <param name="radius">The size of the asteroid.</param>
        public Asteroid(float radius)
            : base()
        {
            // safety-check the parameters
            if (radius <= 0f)
            {
                throw new ArgumentOutOfRangeException("radius");
            }

            // set the collision data
            this.radius = radius;
            this.mass   = this.radius * massRadiusRatio;

            this.Velocity = RandomMath.RandomDirection() *
                            RandomMath.RandomBetween(initialSpeedMinimum, initialSpeedMaximum);
        }