| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- //-----------------------------------------------------------------------------
- // Particle.cs
- //
- // Microsoft XNA Community Game Platform
- // Copyright (C) Microsoft Corporation. All rights reserved.
- //-----------------------------------------------------------------------------
- using System;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Graphics;
- namespace NetRumble
- {
- /// <summary>
- /// A single particle in a particle-based effect.
- /// </summary>
- public class Particle
- {
-
- /// <summary>
- /// The time remaining for this particle.
- /// </summary>
- public float TimeRemaining;
- /// <summary>
- /// The position of this particle.
- /// </summary>
- public Vector2 Position;
- /// <summary>
- /// The velocity of this particle.
- /// </summary>
- public Vector2 Velocity;
- /// <summary>
- /// The acceleration of this particle.
- /// </summary>
- public Vector2 Acceleration;
- /// <summary>
- /// The scale applied to this particle.
- /// </summary>
- public float Scale = 1f;
- /// <summary>
- /// The rotation applied to this particle.
- /// </summary>
- public float Rotation;
- /// <summary>
- /// The opacity of the particle.
- /// </summary>
- public float Opacity = 1f;
- /// <summary>
- /// Update the particle.
- /// </summary>
- /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
- /// <param name="angularVelocity">The angular velocity of the particle.</param>
- /// <param name="scaleDeltaPerSecond">The change in the scale</param>
- /// <param name="opacityDeltaPerSecond">The change in the opacity.</param>
- public void Update(float elapsedTime, float angularVelocity,
- float scaleDeltaPerSecond, float opacityDeltaPerSecond)
- {
- Velocity.X += Acceleration.X * elapsedTime;
- Velocity.Y += Acceleration.Y * elapsedTime;
- Position.X += Velocity.X * elapsedTime;
- Position.Y += Velocity.Y * elapsedTime;
- Rotation += angularVelocity * elapsedTime;
- Scale += scaleDeltaPerSecond * elapsedTime;
- if (Scale < 0f)
- {
- Scale = 0f;
- }
- Opacity = MathHelper.Clamp(Opacity + opacityDeltaPerSecond * elapsedTime,
- 0f, 1f);
- }
- }
- }
|