Ver Mensaje Individual
  #2 (permalink)  
Antiguo 15/11/2008, 09:42
Avatar de jahepi
jahepi
Colaborador
 
Fecha de Ingreso: diciembre-2004
Ubicación: Querétaro
Mensajes: 1.124
Antigüedad: 19 años, 11 meses
Puntos: 43
Respuesta: Ayuda con Código de Juegos Pirotécnicos

Hola Abigor66 !

Prueba con este código:

Código actionscript:
Ver original
  1. import flash.display.*;
  2. import flash.geom.*;
  3. import flash.filters.*;
  4. //============DRAW ELEMENTS===========//
  5. //Fireworks Frame-work
  6. var fw_bit:BitmapData = new BitmapData(Stage.width, Stage.height, true);
  7. var fw_mc:MovieClip = _root.createEmptyMovieClip("fw_mc", _root.getNextHighestDepth());
  8. fw_mc.attachBitmap(fw_bit, this.getNextHighestDepth());
  9. //
  10. //Graphics Management
  11. var baseMatrix = new flash.geom.Matrix();
  12. var fade = new flash.geom.ColorTransform();
  13. fade.alphaMultiplier = 0.9;
  14. //
  15. //Init
  16. var fired:Boolean = false;
  17. var floor:Number = 130;
  18. var launch:Point = new Point(Stage.width/2, floor);
  19. var gravity = .02;
  20. var res = .97;
  21. var max_fw = 4;
  22. var particlecolor = 0xFFFFFFFF;
  23. var particleglowcolor = 0xff0000;
  24. var particles = new Array();
  25. var glow = new GlowFilter(particleglowcolor, 5, 5, 5, 5);
  26. var fw_num:Number = 0;
  27. var interval:Number = 1500;
  28. //
  29. //===========SEQUENCE STATUS=============//
  30. fw_mc.filters = [glow];
  31. fw_mc.blendMode = "add";
  32. //
  33. onEnterFrame = function () {
  34.     fw_bit.colorTransform(fw_bit.rectangle, fade);
  35.     // for all particles in the array
  36.     for (i in particles) {
  37.         currparticle = particles[i];
  38.         // draw the particle at its current location
  39.         fw_bit.setPixel32(currparticle.x, currparticle.y, particlecolor);
  40.         // move it for the next frame
  41.         positionParticle(currparticle);
  42.         for (j in currparticle.fArr) {
  43.             makeExplode_move(currparticle.fArr[j]);
  44.             if(currparticle.fArr[j].det==true){
  45.                 currparticle.fArr[j] = null;
  46.             }
  47.         }
  48.         if(currparticle.exploded == true){
  49.             currparticle.x = Stage.width*2;
  50.             currparticle.y = Stage.height*2;
  51.         }
  52.     }
  53. };
  54.  
  55. var thread:Number = setInterval(threadFunction, interval);
  56. function threadFunction():Void {
  57.     fw_num++;
  58.     var x:Number = Math.random()*Stage.width;
  59.     var y:Number = Math.random()*Stage.height;
  60.     var mousepos = new Point(x, y);
  61.     var mouseangle = Math.atan2(y-launch.y, x-launch.x);
  62.     var mousepower = Point.distance(launch, mousepos)/45;
  63.     particles.unshift(createParticle(launch.x, floor, mouseangle, mousepower));
  64.     // if particles length is greater than maxparticles
  65.     // reduce the particles to be maxparticles
  66.     // since no movie clips are used to manage the
  67.     // particles, no movie clips have to be removed
  68.     if (particles.length>max_fw) {
  69.         particles.length = max_fw;
  70.     }
  71. }
  72. function createParticle(x, y, angle, power) {
  73.     // create new object
  74.     var particle = new Object();
  75.     // assign position values
  76.     particle.x = x;
  77.     particle.y = y;
  78.     particle._initTime = getTimer();
  79.     particle.exploded = false;
  80.     particle.fArr = new Array();
  81.     // develop a random angle based on angle passed and the
  82.     // available spread defined earlier
  83.     angle = -angle;
  84.     // generate a random power value
  85.     power = -power/2+power+power;
  86.     // create vx and vy variables for
  87.     // movement using angle and power
  88.     particle.vx = Math.cos(angle)*power;
  89.     particle.vy = -Math.sin(angle)*power;
  90.     // return particle object
  91.     return particle;
  92. }
  93. //
  94. function positionParticle(particle) {
  95.     var pTime:Number = Math.floor((getTimer()-particle._initTime)/1000);
  96.     // move based on vx and vy
  97.     particle.x += particle.vx;
  98.     particle.y += particle.vy;
  99.     // bounce if it hits the floor
  100.     if (particle.y>floor) {
  101.         makeExplode(particle);
  102.         fired = false;
  103.     }
  104.     // apply gravity to vy            
  105.     particle.vy += gravity;
  106.     particle.vy *= res;
  107.     particle.vx *= res;
  108.     if (pTime>=2) {
  109.         if (particle.exploded == false) {
  110.             particle.fArr = makeExplode(particle, 100);
  111.             fw_num--;
  112.             particle.exploded = true;
  113.         }
  114.     }
  115. }
  116. //
  117. function makeExplode(particle, num) {
  118.     var exArray = new Array();
  119.     for (i=0; i<num; i++) {
  120.         exArray[i] = makeExplode_frag(particle);
  121.     }
  122.     return exArray;
  123. }
  124. //
  125. function makeExplode_frag(particle) {
  126.     var frag = new Object();
  127.     frag.det = false;
  128.     frag._initTime = getTimer();
  129.     frag._dieTime = 2000+random(2000);
  130.     frag.x = particle.x;
  131.     frag.y = particle.y;
  132.     angle = Math.random()*(2*Math.PI);
  133.     power = 1+Math.random()*5;
  134.     frag.vx = Math.cos(angle)*power;
  135.     frag.vy = -Math.sin(angle)*power;
  136.     return frag;
  137. }
  138. //
  139. function makeExplode_move(frag) {
  140.     frag.fTime = Math.floor((getTimer()-frag._initTime));
  141.     frag.x += frag.vx;
  142.     frag.y += frag.vy;
  143.     // bounce if it hits the floor
  144.     // apply gravity to vy      
  145.     frag.vy += gravity/2;
  146.     frag.vy *= res;
  147.     frag.vx *= res;
  148.     fw_bit.setPixel32(frag.x, frag.y, particlecolor);
  149.     if (frag.fTime>=frag._dieTime) {
  150.         if (frag.det == false) {
  151.             frag.det = true;
  152.         }
  153.     }
  154. }


Un saludo !
__________________
Una contraseña es como la ropa interior. No deberías dejarlas afuera a la vista de otras personas, deberías cambiarla regularmente, y ni se te ocurra prestarla a extraños.