Particle.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // Particle.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using Microsoft.Xna.Framework;
  12. using Microsoft.Xna.Framework.Graphics;
  13. #endregion
  14. namespace NetRumble
  15. {
  16. /// <summary>
  17. /// A single particle in a particle-based effect.
  18. /// </summary>
  19. public class Particle
  20. {
  21. #region Status Data
  22. /// <summary>
  23. /// The time remaining for this particle.
  24. /// </summary>
  25. public float TimeRemaining;
  26. #endregion
  27. #region Graphics Data
  28. /// <summary>
  29. /// The position of this particle.
  30. /// </summary>
  31. public Vector2 Position;
  32. /// <summary>
  33. /// The velocity of this particle.
  34. /// </summary>
  35. public Vector2 Velocity;
  36. /// <summary>
  37. /// The acceleration of this particle.
  38. /// </summary>
  39. public Vector2 Acceleration;
  40. /// <summary>
  41. /// The scale applied to this particle.
  42. /// </summary>
  43. public float Scale = 1f;
  44. /// <summary>
  45. /// The rotation applied to this particle.
  46. /// </summary>
  47. public float Rotation;
  48. /// <summary>
  49. /// The opacity of the particle.
  50. /// </summary>
  51. public float Opacity = 1f;
  52. #endregion
  53. #region Updating Methods
  54. /// <summary>
  55. /// Update the particle.
  56. /// </summary>
  57. /// <param name="elapsedTime">The amount of elapsed time, in seconds.</param>
  58. /// <param name="angularVelocity">The angular velocity of the particle.</param>
  59. /// <param name="scaleDeltaPerSecond">The change in the scale</param>
  60. /// <param name="opacityDeltaPerSecond">The change in the opacity.</param>
  61. public void Update(float elapsedTime, float angularVelocity,
  62. float scaleDeltaPerSecond, float opacityDeltaPerSecond)
  63. {
  64. Velocity.X += Acceleration.X * elapsedTime;
  65. Velocity.Y += Acceleration.Y * elapsedTime;
  66. Position.X += Velocity.X * elapsedTime;
  67. Position.Y += Velocity.Y * elapsedTime;
  68. Rotation += angularVelocity * elapsedTime;
  69. Scale += scaleDeltaPerSecond * elapsedTime;
  70. if (Scale < 0f)
  71. {
  72. Scale = 0f;
  73. }
  74. Opacity = MathHelper.Clamp(Opacity + opacityDeltaPerSecond * elapsedTime,
  75. 0f, 1f);
  76. }
  77. #endregion
  78. }
  79. }