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

  1. class Missile
  2. {
  3.    var bAlly;
  4.    var bExp;
  5.    var bmpMissile;
  6.    var bmpCanvas;
  7.    var position;
  8.    var velMax;
  9.    var velLin;
  10.    var velocity;
  11.    var rotation;
  12.    var acc;
  13.    var screenPos;
  14.    var frameExp;
  15.    function Missile(sLinkageId, pos, refTarget, bAllyNew)
  16.    {
  17.       this.bAlly = true;
  18.       this.bExp = false;
  19.       this.bmpMissile = flash.display.BitmapData.loadBitmap(sLinkageId);
  20.       if(this.bAlly)
  21.       {
  22.          this.bmpCanvas = Game.bmpShots;
  23.       }
  24.       else
  25.       {
  26.          this.bmpCanvas = Game.bmpDead;
  27.       }
  28.       this.position = pos.clone();
  29.       this.velMax = 15;
  30.       this.velLin = 0;
  31.       this.velocity = new flash.geom.Point();
  32.       var _loc2_ = refTarget.getPosition();
  33.       var _loc4_ = _loc2_.x - this.position.x;
  34.       var _loc3_ = _loc2_.y - this.position.y;
  35.       this.rotation = Math.atan2(_loc3_,_loc4_);
  36.       this.acc = new flash.geom.Point();
  37.       this.draw();
  38.    }
  39.    function step(refTarget, bAlly)
  40.    {
  41.       if(this.bExp)
  42.       {
  43.          return undefined;
  44.       }
  45.       var _loc6_ = refTarget.getPosition();
  46.       var _loc4_ = _loc6_.x - this.position.x;
  47.       var _loc3_ = _loc6_.y - this.position.y;
  48.       var _loc2_ = Math.atan2(_loc3_,_loc4_);
  49.       var _loc5_ = _loc2_ - this.rotation;
  50.       if(_loc2_ / this.rotation < 0)
  51.       {
  52.          if(_loc2_ > 0 && _loc5_ > 3.141592653589793)
  53.          {
  54.             _loc2_ -= 6.283185307179586;
  55.          }
  56.          else if(_loc2_ < 0 && _loc5_ < -3.141592653589793)
  57.          {
  58.             _loc2_ += 6.283185307179586;
  59.          }
  60.       }
  61.       this.rotation += (_loc2_ - this.rotation) * 0.2;
  62.       var _loc8_ = this.velocity.length;
  63.       if(this.velLin < this.velMax)
  64.       {
  65.          this.velLin += 0.15;
  66.       }
  67.       else
  68.       {
  69.          this.velLin = this.velMax;
  70.       }
  71.       this.velocity.x = this.velLin * Math.cos(this.rotation);
  72.       this.velocity.y = this.velLin * Math.sin(this.rotation);
  73.       this.position.x += this.velocity.x;
  74.       this.position.y += this.velocity.y;
  75.       if(this.screenPos.x < -200 || this.screenPos.x > Game.screenW + 200)
  76.       {
  77.          if(bAlly)
  78.          {
  79.             Game.getInstance().removeAllyMissile(this);
  80.          }
  81.          else
  82.          {
  83.             Game.getInstance().removeHostileMissile(this);
  84.          }
  85.       }
  86.       if(Math.sqrt(_loc4_ * _loc4_ + _loc3_ * _loc3_) < 30)
  87.       {
  88.          refTarget.getDamage(100);
  89.          if(bAlly)
  90.          {
  91.             Game.getInstance().removeAllyMissile(this);
  92.          }
  93.          else
  94.          {
  95.             Game.getInstance().removeHostileMissile(this);
  96.          }
  97.       }
  98.       if(Game.bmpDead.hitTest(new flash.geom.Point(0,0),250,new flash.geom.Point(this.screenPos.x,Game.screenH - this.screenPos.y)))
  99.       {
  100.          this.bExp = true;
  101.          this.frameExp = 0;
  102.       }
  103.    }
  104.    function draw(leftEdge)
  105.    {
  106.       var _loc6_ = this.position.x - leftEdge;
  107.       var _loc5_ = this.position.y;
  108.       this.screenPos = new flash.geom.Point(_loc6_,_loc5_);
  109.       if(this.bExp)
  110.       {
  111.          this.drawExplosion(this.screenPos,true);
  112.       }
  113.       else
  114.       {
  115.          var _loc2_ = new flash.display.BitmapData(this.bmpMissile.width,this.bmpMissile.height,true,0);
  116.          _loc2_.copyPixels(this.bmpMissile,this.bmpMissile.rectangle,new flash.geom.Point(0,0),null,null,true);
  117.          var _loc3_ = new flash.geom.Matrix();
  118.          _loc3_.translate((- _loc2_.width) / 2,(- _loc2_.height) / 2);
  119.          var _loc7_ = new flash.geom.Matrix();
  120.          _loc7_.rotate(- this.rotation);
  121.          _loc3_.concat(_loc7_);
  122.          var _loc4_ = new flash.geom.Matrix();
  123.          _loc4_.translate(_loc6_,Game.screenH - _loc5_);
  124.          _loc3_.concat(_loc4_);
  125.          var _loc9_ = null;
  126.          var _loc8_ = "normal";
  127.          var _loc10_ = null;
  128.          var _loc11_ = true;
  129.          this.bmpCanvas.draw(_loc2_,_loc3_,_loc9_,_loc8_,_loc10_,_loc11_);
  130.       }
  131.    }
  132.    function drawExplosion(pos, bRemove)
  133.    {
  134.       var _loc4_ = _root.attachMovie("explosion0","mcExp",_root.getNextHighestDepth());
  135.       _loc4_.gotoAndStop(this.frameExp + 1);
  136.       var _loc5_ = new flash.geom.Matrix();
  137.       _loc5_.translate(pos.x,Game.screenH - pos.y);
  138.       var _loc3_ = new flash.geom.Matrix();
  139.       _loc3_.scale(0.5,0.5);
  140.       _loc3_.concat(_loc5_);
  141.       this.bmpCanvas.draw(_loc4_,_loc3_,null,null,null,true);
  142.       _loc4_.removeMovieClip();
  143.       this.frameExp = this.frameExp + 1;
  144.       if(this.frameExp == 25)
  145.       {
  146.          if(bRemove)
  147.          {
  148.             this.onEndDeadAnim();
  149.          }
  150.       }
  151.    }
  152.    function onEndDeadAnim(Void)
  153.    {
  154.       if(this.bAlly)
  155.       {
  156.          Game.getInstance().removeAllyMissile(this);
  157.       }
  158.       else
  159.       {
  160.          Game.getInstance().removeHostileMissile(this);
  161.       }
  162.    }
  163.    function findNearest(aObjects)
  164.    {
  165.       var _loc8_ = aObjects.length;
  166.       var _loc5_ = 1.7976931348623157e+308;
  167.       var _loc7_ = null;
  168.       var _loc2_ = 0;
  169.       while(_loc2_ < _loc8_)
  170.       {
  171.          var _loc3_ = aObjects[_loc2_].getPosition();
  172.          _loc3_.subtract(this.position);
  173.          var _loc4_ = _loc3_.length;
  174.          if(_loc4_ < _loc5_)
  175.          {
  176.             _loc5_ = _loc4_;
  177.             _loc7_ = aObjects[_loc2_];
  178.          }
  179.          _loc2_ = _loc2_ + 1;
  180.       }
  181.       return _loc7_;
  182.    }
  183. }
  184.