home *** CD-ROM | disk | FTP | other *** search
/ Champak 106 / Vol 106.iso / games / global_r.swf / scripts / __Packages / Particle.as < prev    next >
Encoding:
Text File  |  2010-04-12  |  1.9 KB  |  62 lines

  1. class Particle
  2. {
  3.    var position;
  4.    var velocity;
  5.    var type;
  6.    var alpha;
  7.    var frame;
  8.    var flightTime;
  9.    var bmpCanvas;
  10.    var screenPos;
  11.    function Particle(pos)
  12.    {
  13.       this.position = pos.clone();
  14.       var _loc3_ = 12 * (1 - 2 * Math.random());
  15.       var _loc2_ = 7 + 9 * Math.random();
  16.       this.velocity = new flash.geom.Point(_loc3_,_loc2_);
  17.       this.type = Math.floor(4 * Math.random());
  18.       this.alpha = 100;
  19.       this.frame = 0;
  20.       this.flightTime = 5 + Math.round(25 * Math.random());
  21.       this.bmpCanvas = Game.bmpShots;
  22.    }
  23.    function getPosition(Void)
  24.    {
  25.       return this.position.clone();
  26.    }
  27.    function step(Void)
  28.    {
  29.       this.velocity.y -= 1.2;
  30.       this.velocity.x *= 0.97;
  31.       this.position.x += this.velocity.x;
  32.       this.position.y += this.velocity.y;
  33.       this.frame = this.frame + 1;
  34.       this.frame %= 4;
  35.       if(this.flightTime-- <= 0 || this.position.y < 0)
  36.       {
  37.          Game.getInstance().removeShrapnel(this);
  38.       }
  39.       else if(this.flightTime < 10)
  40.       {
  41.          this.alpha = 10 * this.flightTime;
  42.       }
  43.    }
  44.    function draw(leftEdge)
  45.    {
  46.       var _loc7_ = this.position.x - leftEdge;
  47.       var _loc6_ = this.position.y;
  48.       this.screenPos = new flash.geom.Point(_loc7_,_loc6_);
  49.       var _loc3_ = _root.attachMovie("shrapnel","mcShr",_root.getNextHighestDepth());
  50.       _loc3_.gotoAndStop(this.type);
  51.       var _loc8_ = (50 + 50 * (30 - this.flightTime) / 30) / 100;
  52.       var _loc4_ = new flash.geom.Matrix();
  53.       _loc4_.scale(_loc8_,_loc8_);
  54.       var _loc5_ = new flash.geom.Matrix();
  55.       _loc5_.translate(_loc7_,Game.screenH - _loc6_);
  56.       _loc4_.concat(_loc5_);
  57.       var _loc9_ = new flash.geom.ColorTransform(1,1,1,this.alpha / 100,0,0,0,0);
  58.       this.bmpCanvas.draw(_loc3_,_loc4_,_loc9_,null,null,true);
  59.       _loc3_.removeMovieClip();
  60.    }
  61. }
  62.