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

  1. class MissileLauncher
  2. {
  3.    var index;
  4.    var bmpBase;
  5.    var bmpHead;
  6.    var bmpExplode;
  7.    var bmpCanvas;
  8.    var position;
  9.    var VEL;
  10.    var energy;
  11.    var frameExp;
  12.    var shotDelay;
  13.    var bOnScreen;
  14.    var bFlash;
  15.    var rotation;
  16.    var screenPos;
  17.    var maxRot = 2.356194490192345;
  18.    var minRot = 0.7853981633974483;
  19.    function MissileLauncher(pos, type, indexNew)
  20.    {
  21.       this.index = indexNew;
  22.       this.bmpBase = flash.display.BitmapData.loadBitmap("ml base");
  23.       this.bmpHead = flash.display.BitmapData.loadBitmap("ml head");
  24.       this.bmpExplode = flash.display.BitmapData.loadBitmap("explosion0");
  25.       this.bmpCanvas = Game.bmpDead;
  26.       this.position = pos.clone();
  27.       this.VEL = 10;
  28.       this.energy = 5;
  29.       this.frameExp = 0;
  30.       this.shotDelay = Math.round(10 * Math.random());
  31.       this.bOnScreen = false;
  32.       this.bFlash = false;
  33.    }
  34.    function getPosition(Void)
  35.    {
  36.       return this.position.clone();
  37.    }
  38.    function step(chopperPos, chopperVel, aShots)
  39.    {
  40.       if(!this.bOnScreen && this.energy > 0)
  41.       {
  42.          return undefined;
  43.       }
  44.       var _loc4_ = aShots.length;
  45.       var _loc3_ = 0;
  46.       while(_loc3_ < _loc4_)
  47.       {
  48.          var _loc2_ = Shot(aShots[_loc3_]);
  49.          var _loc7_ = _loc2_.position.x - this.position.x;
  50.          var _loc6_ = _loc2_.position.y - this.position.y;
  51.          if(_loc7_ * _loc7_ + _loc6_ * _loc6_ < 400)
  52.          {
  53.             Game.getInstance().removeAllyShot(_loc2_);
  54.             this.energy = this.energy - 1;
  55.             this.bFlash = true;
  56.             Game.getInstance().createShrapnel(_loc2_.position);
  57.             if(this.energy == 0)
  58.             {
  59.                Game.getInstance().saveHostileInd(this.index);
  60.                Game.getInstance().addPoints(this.position,500);
  61.                Sounds.playSound("bazooka");
  62.                trace("destroyed");
  63.             }
  64.             break;
  65.          }
  66.          _loc3_ = _loc3_ + 1;
  67.       }
  68.       _loc7_ = chopperPos.x - this.position.x;
  69.       _loc6_ = chopperPos.y - this.position.y;
  70.       this.rotation = Math.atan2(_loc6_,_loc7_);
  71.       if(this.rotation > this.maxRot)
  72.       {
  73.          this.rotation = this.maxRot;
  74.       }
  75.       else if(this.rotation < this.minRot)
  76.       {
  77.          this.rotation = this.minRot;
  78.       }
  79.       if(this.shotDelay-- <= 0)
  80.       {
  81.          this.shotDelay = 90 + Math.round(60 * Math.random());
  82.          var _loc8_ = new flash.geom.Point(this.position.x + 30 * Math.cos(this.rotation),this.position.y + 30 * Math.sin(this.rotation));
  83.          Game.getInstance().createMissile(false,_loc8_,null);
  84.          Sounds.playSound("missile_snd");
  85.       }
  86.    }
  87.    function draw(leftEdge)
  88.    {
  89.       var _loc8_ = this.position.x - leftEdge - this.bmpBase.width / 2;
  90.       var _loc7_ = this.position.y + this.bmpBase.height / 2;
  91.       this.screenPos = new flash.geom.Point(_loc8_,_loc7_);
  92.       if(_loc8_ > (- this.bmpBase.width) * 1 && _loc8_ < Game.screenW + this.bmpBase.width * 0.5)
  93.       {
  94.          this.bOnScreen = true;
  95.          if(this.energy > 0)
  96.          {
  97.             var _loc2_ = new flash.display.BitmapData(this.bmpHead.width,this.bmpHead.height,true,0);
  98.             _loc2_.copyPixels(this.bmpHead,this.bmpHead.rectangle,new flash.geom.Point(0,0),null,null,true);
  99.             var _loc3_ = new flash.geom.Matrix();
  100.             _loc3_.translate((- _loc2_.width) / 2,(- _loc2_.height) / 2);
  101.             var _loc6_ = new flash.geom.Matrix();
  102.             _loc6_.rotate(- this.rotation);
  103.             _loc3_.concat(_loc6_);
  104.             var _loc5_ = new flash.geom.Matrix();
  105.             _loc5_.translate(_loc8_ + this.bmpBase.width * 0.5,Game.screenH - (_loc7_ - this.bmpBase.height + 22));
  106.             _loc3_.concat(_loc5_);
  107.             var _loc9_ = !this.bFlash ? null : new flash.geom.ColorTransform(0,0,0,0,255,255,255,255);
  108.             this.bmpCanvas.draw(_loc2_,_loc3_,_loc9_,null,null,true);
  109.             var _loc4_ = this.bmpBase.clone();
  110.             if(this.bFlash)
  111.             {
  112.                _loc4_.colorTransform(_loc4_.rectangle,new flash.geom.ColorTransform(0,0,0,0,255,255,255,255));
  113.             }
  114.             this.bmpCanvas.copyPixels(_loc4_,_loc4_.rectangle,new flash.geom.Point(this.screenPos.x,Game.screenH - this.screenPos.y),null,null,true);
  115.             this.bFlash = false;
  116.          }
  117.          else
  118.          {
  119.             _loc8_ = this.position.x - leftEdge;
  120.             _loc7_ = this.position.y;
  121.             this.screenPos = new flash.geom.Point(_loc8_,_loc7_);
  122.             this.drawExplosion(this.screenPos,true);
  123.          }
  124.       }
  125.       else
  126.       {
  127.          this.bOnScreen = false;
  128.       }
  129.    }
  130.    function drawExplosion(pos, bRemove)
  131.    {
  132.       var _loc3_ = _root.attachMovie("explosion2","mcExp",_root.getNextHighestDepth());
  133.       _loc3_.gotoAndStop(this.frameExp + 1);
  134.       var _loc4_ = new flash.geom.Matrix();
  135.       _loc4_.translate(pos.x,Game.screenH - pos.y);
  136.       this.bmpCanvas.draw(_loc3_,_loc4_,null,null,null,true);
  137.       _loc3_.removeMovieClip();
  138.       this.frameExp = this.frameExp + 1;
  139.       if(this.frameExp == 27)
  140.       {
  141.          if(bRemove)
  142.          {
  143.             this.onEndDeadAnim();
  144.          }
  145.       }
  146.    }
  147.    function onEndDeadAnim(Void)
  148.    {
  149.       Game.getInstance().removeHostile(this);
  150.    }
  151. }
  152.