Advertisement
shaheen916

Flash Fireworks actionscript

Apr 2nd, 2013
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. // Action script...
  2.  
  3. // [Action in Frame 1]
  4. function createParticle(x, y, angle, power)
  5. {
  6. var _loc1 = new Object();
  7. _loc1.x = x;
  8. _loc1.y = y;
  9. _loc1._initTime = getTimer();
  10. _loc1.exploded = false;
  11. _loc1.fArr = new Array();
  12. angle = -angle;
  13. power = -power / 2 + power + power;
  14. _loc1.vx = Math.cos(angle) * power;
  15. _loc1.vy = -Math.sin(angle) * power;
  16. return (_loc1);
  17. } // End of the function
  18. function positionParticle(particle)
  19. {
  20. var _loc2 = Math.floor((getTimer() - particle._initTime) / 1000);
  21. particle.x = particle.x + particle.vx;
  22. particle.y = particle.y + particle.vy;
  23. if (particle.y > floor)
  24. {
  25. makeExplode(particle);
  26. fired = false;
  27. } // end if
  28. particle.vy = particle.vy + gravity;
  29. particle.vy = particle.vy * res;
  30. particle.vx = particle.vx * res;
  31. if (_loc2 >= 2)
  32. {
  33. if (particle.exploded == false)
  34. {
  35. particle.fArr = makeExplode(particle, 100);
  36. --fw_num;
  37. particle.exploded = true;
  38. } // end if
  39. false;
  40. } // end if
  41. } // End of the function
  42. function makeExplode(particle, num)
  43. {
  44. var _loc1 = new Array();
  45. for (i = 0; i < num; i++)
  46. {
  47. _loc1[i] = makeExplode_frag(particle);
  48. } // end of for
  49. return (_loc1);
  50. } // End of the function
  51. function makeExplode_frag(particle)
  52. {
  53. var _loc1 = new Object();
  54. _loc1.det = false;
  55. _loc1._initTime = getTimer();
  56. _loc1._dieTime = 2000 + random(2000);
  57. _loc1.x = particle.x;
  58. _loc1.y = particle.y;
  59. angle = Math.random() * 6.283185;
  60. power = 1 + Math.random() * 4;
  61. _loc1.vx = Math.cos(angle) * power;
  62. _loc1.vy = -Math.sin(angle) * power;
  63. return (_loc1);
  64. } // End of the function
  65. function makeExplode_move(frag)
  66. {
  67. frag.fTime = Math.floor(getTimer() - frag._initTime);
  68. frag.x = frag.x + frag.vx;
  69. frag.y = frag.y + frag.vy;
  70. frag.vy = frag.vy + gravity / 2;
  71. frag.vy = frag.vy * res;
  72. frag.vx = frag.vx * res;
  73. fw_bit.setPixel32(frag.x, frag.y, particlecolor);
  74. if (frag.fTime >= frag._dieTime)
  75. {
  76. if (frag.det == false)
  77. {
  78. frag.det = true;
  79. } // end if
  80. } // end if
  81. } // End of the function
  82. Stage.scaleMode = "noScale";
  83. var bg_bit = new flash.display.BitmapData(Stage.width, Stage.height, false, 0);
  84. var bg_mc = _root.createEmptyMovieClip("bg_mc", _root.getNextHighestDepth());
  85. bg_mc.attachBitmap(bg_bit, this.getNextHighestDepth());
  86. var fw_bit = new flash.display.BitmapData(Stage.width, Stage.height, true);
  87. var fw_mc = _root.createEmptyMovieClip("fw_mc", _root.getNextHighestDepth());
  88. fw_mc.attachBitmap(fw_bit, this.getNextHighestDepth());
  89. var baseMatrix = new flash.geom.Matrix();
  90. var fade = new flash.geom.ColorTransform();
  91. fade.alphaMultiplier = 0.900000;
  92. var fired = false;
  93. var floor = 375;
  94. var launch = new flash.geom.Point(Stage.width / 2, floor);
  95. var gravity = 0.020000;
  96. var res = 0.970000;
  97. var max_fw = 3;
  98. var particlecolor = 4294967295.000000;
  99. var particleglowcolor = 65280;
  100. var particles = new Array();
  101. var glow = new flash.filters.GlowFilter(particleglowcolor, 10, 10, 10, 10);
  102. var fw_num = 0;
  103. fw_mc.filters = [glow];
  104. fw_mc.blendMode = "add";
  105. onEnterFrame = function ()
  106. {
  107. if (fw_num < max_fw)
  108. {
  109. fw_mc.onPress = function ()
  110. {
  111. ++fw_num;
  112. var _loc1 = new flash.geom.Point(_xmouse, _ymouse);
  113. var _loc2 = Math.atan2(_loc1.y - launch.y, _loc1.x - launch.x);
  114. var _loc3 = flash.geom.Point.distance(launch, _loc1) / 45;
  115. particles.unshift(createParticle(launch.x, floor, _loc2, _loc3));
  116. if (particles.length > max_fw)
  117. {
  118. particles.length = max_fw;
  119. } // end if
  120. };
  121. }
  122. else
  123. {
  124. delete fw_mc.onPress;
  125. } // end else if
  126. fw_bit.colorTransform(fw_bit.rectangle, fade);
  127. for (i in particles)
  128. {
  129. currparticle = particles[i];
  130. fw_bit.setPixel32(currparticle.x, currparticle.y, particlecolor);
  131. positionParticle(currparticle);
  132. for (j in currparticle.fArr)
  133. {
  134. makeExplode_move(currparticle.fArr[j]);
  135. if (currparticle.fArr[j].det == true)
  136. {
  137. currparticle.fArr[j] = null;
  138. } // end if
  139. } // end of for...in
  140. if (currparticle.exploded == true)
  141. {
  142. currparticle.x = Stage.width * 2;
  143. currparticle.y = Stage.height * 2;
  144. } // end if
  145. } // end of for...in
  146. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement