/Flash project/src/com/danta/radialFortress/components/EnemyBullet.as

https://github.com/just-granada/RadialFortress
ActionScript | 162 lines | 63 code | 29 blank | 70 comment | 1 complexity | f0f982ae80507d97aed9ee687fc927ef MD5 | raw file
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Zemoga Inc
  4. // Copyright 2011 Zemoga Inc
  5. // All Rights Reserved.
  6. //
  7. ////////////////////////////////////////////////////////////////////////////////
  8. package com.danta.radialFortress.components
  9. {
  10. import com.danta.radialFortress.FortressEvent;
  11. import com.danta.radialfortress.lib.Beam;
  12. import com.danta.util.ArcHelper;
  13. import flash.display.BlendMode;
  14. import flash.display.Sprite;
  15. import flash.filters.GlowFilter;
  16. /**
  17. * Class description here
  18. *
  19. * @author camilosoto <email>
  20. */
  21. public class EnemyBullet extends Sprite
  22. {
  23. //------------------------------------------------------------------------------
  24. //
  25. // Constants
  26. //
  27. //------------------------------------------------------------------------------
  28. //--------------------------------------
  29. // Public
  30. //--------------------------------------
  31. public static var BULLET_SPEED:Number=0.2;
  32. //--------------------------------------
  33. // Private
  34. //--------------------------------------
  35. //------------------------------------------------------------------------------
  36. //
  37. // Static Methods
  38. //
  39. //------------------------------------------------------------------------------
  40. ////////////////////////////////////////////////////////////////////////////////
  41. //
  42. // Constructor
  43. //
  44. ////////////////////////////////////////////////////////////////////////////////
  45. public function EnemyBullet(angularPosition:Number, radialDistance:Number)
  46. {
  47. createBody();
  48. this.radialVelocity=BULLET_SPEED;
  49. this.radialDistance=radialDistance;
  50. this.angularPosition=angularPosition;
  51. rotation=ArcHelper.toDeg(-angularPosition);
  52. this.x=Math.sin(angularPosition)*radialDistance;
  53. this.y=Math.cos(angularPosition)*radialDistance;
  54. }
  55. //------------------------------------------------------------------------------
  56. //
  57. // Variables
  58. //
  59. //------------------------------------------------------------------------------
  60. //--------------------------------------
  61. // Public
  62. //--------------------------------------
  63. //--------------------------------------
  64. // Private
  65. //--------------------------------------
  66. private var _angularPosition:Number;
  67. private var _radialDistance:Number;
  68. private var radialVelocity:Number;
  69. private var lastDeltaT:Number;
  70. //------------------------------------------------------------------------------
  71. //
  72. // Properties (getters/setters)
  73. //
  74. //------------------------------------------------------------------------------
  75. //------------------------------------------------------------------------------
  76. //
  77. // Overriden methods
  78. //
  79. //------------------------------------------------------------------------------
  80. //------------------------------------------------------------------------------
  81. //
  82. // Methods
  83. //
  84. //------------------------------------------------------------------------------
  85. //--------------------------------------
  86. // Public
  87. //--------------------------------------
  88. public function get angularPosition():Number
  89. {
  90. return _angularPosition;
  91. }
  92. public function set angularPosition(value:Number):void
  93. {
  94. _angularPosition = value;
  95. }
  96. public function get radialDistance():Number
  97. {
  98. return _radialDistance;
  99. }
  100. public function get collisionRadialDistances():Array
  101. {
  102. return [_radialDistance, radialDistance+radialVelocity*lastDeltaT];
  103. }
  104. public function set radialDistance(value:Number):void
  105. {
  106. _radialDistance = value;
  107. }
  108. public function draw(deltaT:uint):void
  109. {
  110. radialDistance+=radialVelocity*deltaT;
  111. this.x=Math.sin(angularPosition)*radialDistance;
  112. this.y=Math.cos(angularPosition)*radialDistance;
  113. if(radialDistance<=0)
  114. {
  115. dispatchEvent(new FortressEvent(FortressEvent.BULLET_REACHED_CENTER));
  116. }
  117. lastDeltaT=deltaT;
  118. }
  119. //--------------------------------------
  120. // Private
  121. //--------------------------------------
  122. private function createBody():void
  123. {
  124. this.addChild(new Beam());
  125. this.filters=[new GlowFilter(0xff0000,1,3,8,4)];
  126. }
  127. //------------------------------------------------------------------------------
  128. //
  129. // Event Handlers
  130. //
  131. //------------------------------------------------------------------------------
  132. }
  133. }