Guest User

Untitled

a guest
Jun 21st, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.75 KB | None | 0 0
  1. init();
  2.  
  3. function init() {
  4. angle = 0;
  5. r = w._width/2;
  6. rspeed = 0;
  7. maxspeed = Math.PI/30;
  8. a._x = (a._width/2)*-1;
  9. a._y = (a._height/2)*-1;
  10. a.speed = 2;
  11. b.speed = 1;
  12. i = 0;
  13. u = 0;
  14. maxi = 0;
  15. a.sec = 0;
  16. b._x = g._x;
  17. b._y = g._y;
  18. firedelay = 10;
  19. firewait = false;
  20. }
  21.  
  22. _root.onEnterFrame = function() {
  23. gunmove();
  24. gunfire();
  25. enemy();
  26. moveEnemy();
  27. moveBullets();
  28.  
  29. };
  30.  
  31. function gunmove() {
  32.  
  33. if (Key.isDown(Key.LEFT)) {
  34. rspeed = rspeed-Math.PI/200;
  35. } else if (Key.isDown(Key.RIGHT)) {
  36. rspeed = rspeed+Math.PI/200;
  37. } else {
  38. if (rspeed<0) {
  39. rspeed = rspeed+Math.PI/200;
  40. }
  41. if (rspeed>0) {
  42. rspeed = rspeed-Math.PI/200;
  43. }
  44. }
  45. if ((rspeed<Math.PI/200) && (rspeed>-Math.PI/200)) {
  46. rspeed = 0;
  47. }
  48. if (rspeed>maxspeed) {
  49. rspeed = maxspeed;
  50. } else if (rspeed<(maxspeed*-1)) {
  51. rspeed = maxspeed*-1;
  52. }
  53. angle = angle+rspeed;
  54.  
  55. if(angle > Math.PI*2) {
  56. angle = angle - (Math.PI*2);
  57. } else if(angle< (Math.PI*2*-1)) {
  58. angle = angle + (Math.PI*2);
  59. }
  60.  
  61. g._rotation = (angle*180)/Math.PI;
  62.  
  63. g._x = w._x+(r*Math.sin(angle));
  64. g._y = w._y-(r*Math.cos(angle));
  65. }
  66.  
  67. function gunfire() {
  68. b._x = g._x;
  69. b._y = g._y;
  70. if (firetimer>0) {
  71. firetimer -= 1;
  72. if (firetimer == 0) {
  73. firewait = false;
  74. }
  75. }
  76. if (Key.isDown(Key.SPACE)) {
  77. if (firewait == false) {
  78. u = u+1;
  79. duplicateMovieClip(b, "b"+u, u);
  80. currentb = eval("b"+u);
  81. currentb.dx = b.speed*Math.cos(angle-Math.PI/2);
  82. currentb.dy = b.speed*Math.sin(angle-Math.PI/2);
  83. firewait = true;
  84. firetimer = firedelay;
  85. }
  86. }
  87. }
  88.  
  89. function enemy() {
  90. timer = random(20);
  91. if (timer == 1) {
  92. i = i+1;
  93. duplicateMovieClip(_root.a, "a"+i, i);
  94. currenta = eval("a"+i);
  95. rand = random(4)+1;
  96. if (rand == 1) {
  97. currenta.sec = 1;
  98. currenta._x = random(Stage.width);
  99. currenta._y = (a._height/2)*-1;
  100. currenta.dx = random(a.speed)+1;
  101. currenta.dy = random(a.speed)+1;
  102. } else if (rand == 2) {
  103. currenta.sec = 2;
  104. currenta._x = random(Stage.width);
  105. currenta._y = Stage.height+(a._height/2);
  106. currenta.dx = random(a.speed)+1;
  107. currenta.dy = (random(a.speed)+1)*-1;
  108. } else if (rand == 3) {
  109. currenta.sec = 3;
  110. currenta._x = (a._width/2)*-1;
  111. currenta._y = random(Stage.height);
  112. currenta.dx = random(a.speed)+1;
  113. currenta.dy = random(a.speed*2)-a.speed;
  114. } else if (rand == 4) {
  115. currenta.sec = 4;
  116. currenta._x = Stage.width+a._width/2;
  117. currenta._y = random(Stage.height);
  118. currenta.dx = (random(a.speed)+1)*-1;
  119. currenta.dy = random(a.speed*2)-a.speed;
  120. }
  121. }
  122. }
  123.  
  124. function moveEnemy() {
  125. if (i>0) {
  126. for (h=i; h>0; h--) {
  127. currenta = eval("a"+h);
  128. currenta._x += currenta.dx;
  129. currenta._y += currenta.dy;
  130. if ((currenta._x>Stage.width+currenta._width/2) && currenta.dx>0) {
  131. removeMovieClip(currenta);
  132. } else if ((currenta._x<-currenta._width/2) && (currenta.dx<0)) {
  133. removeMovieClip(currenta);
  134. } else if ((currenta._y>Stage.height+currenta._height/2) && (currenta.dy>0)) {
  135. removeMovieClip(currenta);
  136. } else if ((currenta._y<-currenta._height/2) && (currenta.dy<0)) {
  137. removeMovieClip(currenta);
  138. }
  139. }
  140. }
  141. }
  142.  
  143. function moveBullets() {
  144. if (u>0) {
  145. for (j=u; j>0; j--) {
  146. currentb = eval("b"+j);
  147. currentb._x += currentb.dx;
  148. currentb._y += currentb.dy;
  149. if ((currentb._x>Stage.width+currentb._width/2) && currentb.dx>0) {
  150. removeMovieClip(currentb);
  151. u--;
  152. } else if ((currentb._x<-currentb._width/2) && (currentb.dx<0)) {
  153. removeMovieClip(currentb);
  154. u--;
  155. } else if ((currentb._y>Stage.height+currentb._height/2) && (currentb.dy>0)) {
  156. removeMovieClip(currentb);
  157. u--;
  158. } else if ((currentb._y<-currentb._height/2) && (currentb.dy<0)) {
  159. removeMovieClip(currentb);
  160. }
  161. }
  162. }
  163. }
Add Comment
Please, Sign In to add comment