예제 #1
0
        /// <summary>
        /// Deep copy all of the Particle properties
        /// </summary>
        /// <param name="ParticleToCopy">The Particle to Copy the properties from</param>
        public override void CopyFrom(DPSFParticle ParticleToCopy)
        {
            // Cast the Particle to the type it really is
            DefaultSpriteParticle cParticleToCopy = (DefaultSpriteParticle)ParticleToCopy;

            base.CopyFrom(cParticleToCopy);
            this.Rotation = cParticleToCopy.Rotation;
            this.Width    = cParticleToCopy.Width;
            this.Height   = cParticleToCopy.Height;
            this.FlipMode = cParticleToCopy.FlipMode;

            this.RotationalVelocity     = cParticleToCopy.RotationalVelocity;
            this.RotationalAcceleration = cParticleToCopy.RotationalAcceleration;

            this.StartWidth  = cParticleToCopy.StartWidth;
            this.StartHeight = cParticleToCopy.StartHeight;
            this.EndWidth    = cParticleToCopy.EndWidth;
            this.EndHeight   = cParticleToCopy.EndHeight;
        }
예제 #2
0
        //===========================================================
        // Initialization Function
        //===========================================================

        /// <summary>
        /// Function to Initialize a Default Particle with default Properties
        /// </summary>
        /// <param name="Particle">The Particle to be Initialized</param>
        public override void InitializeParticleUsingInitialProperties(DPSFParticle Particle)
        {
            // Cast the Particle to the type it really is
            DefaultSpriteParticle cParticle = (DefaultSpriteParticle)Particle;

            // Initialize the Particle according to the values specified in the Initial Settings
            base.InitializeParticleUsingInitialProperties(cParticle, mcInitialProperties);

            // Calculate the Particle's Rotation values
            cParticle.Rotation               = DPSFHelper.RandomNumberBetween(mcInitialProperties.RotationMin, mcInitialProperties.RotationMax);
            cParticle.RotationalVelocity     = DPSFHelper.RandomNumberBetween(mcInitialProperties.RotationalVelocityMin, mcInitialProperties.RotationalVelocityMax);
            cParticle.RotationalAcceleration = DPSFHelper.RandomNumberBetween(mcInitialProperties.RotationalAccelerationMin, mcInitialProperties.RotationalAccelerationMax);

            // Calculate the Particle's Width and Height values
            cParticle.StartWidth  = DPSFHelper.RandomNumberBetween(mcInitialProperties.StartSizeMin > 0 ? mcInitialProperties.StartSizeMin : mcInitialProperties.StartWidthMin, mcInitialProperties.StartSizeMax > 0 ? mcInitialProperties.StartSizeMax : mcInitialProperties.StartWidthMax);
            cParticle.EndWidth    = DPSFHelper.RandomNumberBetween(mcInitialProperties.EndSizeMin > 0 ? mcInitialProperties.EndSizeMin : mcInitialProperties.EndWidthMin, mcInitialProperties.EndSizeMax > 0 ? mcInitialProperties.EndSizeMax : mcInitialProperties.EndWidthMax);
            cParticle.StartHeight = DPSFHelper.RandomNumberBetween(mcInitialProperties.StartSizeMin > 0 ? mcInitialProperties.StartSizeMin : mcInitialProperties.StartHeightMin, mcInitialProperties.StartSizeMax > 0 ? mcInitialProperties.StartSizeMax : mcInitialProperties.StartHeightMax);
            cParticle.EndHeight   = DPSFHelper.RandomNumberBetween(mcInitialProperties.EndSizeMin > 0 ? mcInitialProperties.EndSizeMin : mcInitialProperties.EndHeightMin, mcInitialProperties.EndSizeMax > 0 ? mcInitialProperties.EndSizeMax : mcInitialProperties.EndHeightMax);
            cParticle.Width       = cParticle.StartWidth;
            cParticle.Height      = cParticle.StartHeight;
        }
예제 #3
0
        //===========================================================
        // Draw Sprite and Overridden Particle System Functions
        //===========================================================

        /// <summary>
        /// Function to draw a Sprite Particle. This function should be used to draw the given
        /// Particle with the provided SpriteBatch.
        /// </summary>
        /// <param name="Particle">The Particle Sprite to Draw</param>
        /// <param name="cSpriteBatch">The SpriteBatch to use to doing the Drawing</param>
        protected override void DrawSprite(DPSFParticle Particle, SpriteBatch cSpriteBatch)
        {
            // Cast the Particle to the type it really is
            DefaultSpriteParticle cParticle = (DefaultSpriteParticle)Particle;

            // Get the Position and Dimensions of the Particle in 2D space
            Rectangle sDestination = new Rectangle((int)cParticle.Position.X, (int)cParticle.Position.Y,
                                                   (int)cParticle.Width, (int)cParticle.Height);

            // Get the Depth (Z-Buffer value) of the Particle clamped in the range 0.0 - 1.0 (0.0 = front, 1.0 = back)
            float fNormalizedDepth = MathHelper.Clamp(cParticle.Position.Z, 0.0f, 1.0f);

            // Get the Position and Dimensions from the Texture to use for this Sprite
            Rectangle sSourceFromTexture = new Rectangle(0, 0, Texture.Width, Texture.Height);

            // Make the Sprite rotate about its center
            Vector2 sOrigin = new Vector2(sSourceFromTexture.Width / 2, sSourceFromTexture.Height / 2);

            // Draw the Sprite
            cSpriteBatch.Draw(Texture, sDestination, sSourceFromTexture, cParticle.Color, cParticle.Rotation, sOrigin, cParticle.FlipMode, fNormalizedDepth);
        }
예제 #4
0
 /// <summary>
 /// Linearly interpolate the Particle's Position.Z value from 0.0 (front) to
 /// 1.0 (back) according to the Particle's Normalized Lifetime
 /// </summary>
 /// <param name="cParticle">The Particle to update</param>
 /// <param name="fElapsedTimeInSeconds">How long it has been since the last update</param>
 protected void UpdateParticleDepthFromFrontToBackUsingLerp(DefaultSpriteParticle cParticle, float fElapsedTimeInSeconds)
 {
     // Update the Particle's Depth Position
     cParticle.Position.Z = (cParticle.NormalizedElapsedTime);
 }
예제 #5
0
 /// <summary>
 /// Linearly interpolate the Particle's Width and Height between the Start and End values according
 /// to the Particle's Normalized Lifetime
 /// </summary>
 /// <param name="cParticle">The Particle to update</param>
 /// <param name="fElapsedTimeInSeconds">How long it has been since the last update</param>
 protected void UpdateParticleWidthAndHeightUsingLerp(DefaultSpriteParticle cParticle, float fElapsedTimeInSeconds)
 {
     // Calculate the Particle's new Width and Height
     cParticle.Width  = MathHelper.Lerp(cParticle.StartWidth, cParticle.EndWidth, cParticle.NormalizedElapsedTime);
     cParticle.Height = MathHelper.Lerp(cParticle.StartHeight, cParticle.EndHeight, cParticle.NormalizedElapsedTime);
 }
예제 #6
0
 /// <summary>
 /// Update a Particle's Rotation and Rotational Velocity according to its Rotational Acceleration
 /// </summary>
 /// <param name="cParticle">The Particle to update</param>
 /// <param name="fElapsedTimeInSeconds">How long it has been since the last update</param>
 protected void UpdateParticleRotationAndRotationalVelocityUsingRotationalAcceleration(DefaultSpriteParticle cParticle, float fElapsedTimeInSeconds)
 {
     // Update the Particle's Rotational Velocity and Rotation according to its Rotational Acceleration
     cParticle.RotationalVelocity += cParticle.RotationalAcceleration * fElapsedTimeInSeconds;
     cParticle.Rotation           += cParticle.RotationalVelocity * fElapsedTimeInSeconds;
 }
예제 #7
0
        //===========================================================
        // Particle Update Functions
        //===========================================================

        /// <summary>
        /// Update a Particle's Rotation according to its Rotational Velocity
        /// </summary>
        /// <param name="cParticle">The Particle to update</param>
        /// <param name="fElapsedTimeInSeconds">How long it has been since the last update</param>
        protected void UpdateParticleRotationUsingRotationalVelocity(DefaultSpriteParticle cParticle, float fElapsedTimeInSeconds)
        {
            // Update the Particle's Rotation according to its Rotational Velocity
            cParticle.Rotation += cParticle.RotationalVelocity * fElapsedTimeInSeconds;
        }