Particle.cs 2.5 KB

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