VelocityComponent.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #region File description
  2. // --------------------------------------------------------------------------------------------------------------------
  3. // <copyright file="VelocityComponent.cs" company="GAMADU.COM">
  4. // Copyright © 2013 GAMADU.COM. All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without modification, are
  7. // permitted provided that the following conditions are met:
  8. //
  9. // 1. Redistributions of source code must retain the above copyright notice, this list of
  10. // conditions and the following disclaimer.
  11. //
  12. // 2. Redistributions in binary form must reproduce the above copyright notice, this list
  13. // of conditions and the following disclaimer in the documentation and/or other materials
  14. // provided with the distribution.
  15. //
  16. // THIS SOFTWARE IS PROVIDED BY GAMADU.COM 'AS IS' AND ANY EXPRESS OR IMPLIED
  17. // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  18. // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GAMADU.COM OR
  19. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  22. // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  23. // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  24. // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. //
  26. // The views and conclusions contained in the software and documentation are those of the
  27. // authors and should not be interpreted as representing official policies, either expressed
  28. // or implied, of GAMADU.COM.
  29. // </copyright>
  30. // <summary>
  31. // The velocity.
  32. // </summary>
  33. // --------------------------------------------------------------------------------------------------------------------
  34. #endregion File description
  35. namespace StarWarrior.Components
  36. {
  37. #region Using statements
  38. using System;
  39. using Artemis.Interface;
  40. #endregion
  41. /// <summary>The velocity.</summary>
  42. internal class VelocityComponent : IComponent
  43. {
  44. /// <summary>To radians.</summary>
  45. private const float ToRadians = (float)(Math.PI / 180.0);
  46. /// <summary>Initializes a new instance of the <see cref="VelocityComponent" /> class.</summary>
  47. public VelocityComponent()
  48. : this(0.0f, 0.0f)
  49. {
  50. }
  51. /// <summary>Initializes a new instance of the <see cref="VelocityComponent" /> class.</summary>
  52. /// <param name="velocity">The velocity.</param>
  53. public VelocityComponent(float velocity)
  54. : this(velocity, 0.0f)
  55. {
  56. }
  57. /// <summary>Initializes a new instance of the <see cref="VelocityComponent" /> class.</summary>
  58. /// <param name="velocity">The velocity.</param>
  59. /// <param name="angle">The angle.</param>
  60. public VelocityComponent(float velocity, float angle)
  61. {
  62. this.Speed = velocity;
  63. this.Angle = angle;
  64. }
  65. /// <summary>Gets or sets the angle.</summary>
  66. /// <value>The angle.</value>
  67. public float Angle { get; set; }
  68. /// <summary>Gets the angle as radians.</summary>
  69. /// <value>The angle as radians.</value>
  70. public float AngleAsRadians
  71. {
  72. get
  73. {
  74. return this.Angle * ToRadians;
  75. }
  76. }
  77. /// <summary>Gets or sets the speed.</summary>
  78. /// <value>The speed.</value>
  79. public float Speed { get; set; }
  80. /// <summary>The add angle.</summary>
  81. /// <param name="angle">The angle.</param>
  82. public void AddAngle(float angle)
  83. {
  84. this.Angle = (this.Angle + angle) % 360;
  85. }
  86. }
  87. }