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

  1. class Shot implements WorkObject
  2. {
  3.    var bmpShot;
  4.    var bmpCanvas;
  5.    var position;
  6.    var velocity;
  7.    var acc;
  8.    var rotation;
  9.    var ct;
  10.    var colorInd;
  11.    var bChopper;
  12.    var screenPos;
  13.    function Shot(sLinkageId, pos, vel)
  14.    {
  15.       this.bmpShot = flash.display.BitmapData.loadBitmap(sLinkageId);
  16.       this.bmpCanvas = Game.bmpShots;
  17.       this.position = pos.clone();
  18.       this.position.x -= this.bmpShot.width / 2;
  19.       this.position.y -= this.bmpShot.height / 2;
  20.       this.velocity = vel.clone();
  21.       var _loc4_ = vel.x * 0.05;
  22.       var _loc3_ = vel.y * 0.05;
  23.       this.acc = new flash.geom.Point(_loc4_,_loc3_);
  24.       this.rotation = Math.atan2(vel.y,vel.x);
  25.       var _loc5_ = Math.random();
  26.       this.ct = new flash.geom.ColorTransform(_loc5_,1,1,1,0,0,0,0);
  27.       this.colorInd = Math.floor(180 * Math.random());
  28.       this.bChopper = true;
  29.    }
  30.    function step(Void)
  31.    {
  32.       this.velocity.x += this.acc.x;
  33.       this.velocity.y += this.acc.y;
  34.       this.position.x += this.velocity.x;
  35.       this.position.y += this.velocity.y;
  36.       if(this.bChopper)
  37.       {
  38.          if(this.checkCollision() || this.position.y < 20)
  39.          {
  40.             Game.getInstance().removeAllyShot(this);
  41.          }
  42.       }
  43.       if(this.screenPos.y < 0 || this.screenPos.y > Game.screenH || this.screenPos.x < 0 || this.screenPos.x > Game.screenW)
  44.       {
  45.          Game.getInstance().removeAllyShot(this);
  46.       }
  47.    }
  48.    function draw(leftEdge)
  49.    {
  50.       var _loc6_ = this.position.x - leftEdge;
  51.       var _loc5_ = this.position.y;
  52.       this.screenPos = new flash.geom.Point(_loc6_,_loc5_);
  53.       var _loc2_ = new flash.display.BitmapData(this.bmpShot.width,this.bmpShot.height,true,0);
  54.       _loc2_.copyPixels(this.bmpShot,this.bmpShot.rectangle,new flash.geom.Point(0,0),null,null,true);
  55.       var _loc3_ = new flash.geom.Matrix();
  56.       _loc3_.translate((- _loc2_.width) / 2,(- _loc2_.height) / 2);
  57.       var _loc7_ = new flash.geom.Matrix();
  58.       _loc7_.rotate(- this.rotation);
  59.       _loc3_.concat(_loc7_);
  60.       var _loc4_ = new flash.geom.Matrix();
  61.       _loc4_.translate(_loc6_,Game.screenH - _loc5_);
  62.       _loc3_.concat(_loc4_);
  63.       if(this.ct != null)
  64.       {
  65.          this.colorInd += 600;
  66.          var _loc12_ = 0.2 + 0.8 * (Math.sin(3.141592653589793 * this.colorInd / 180) + 1) / 2;
  67.          this.ct = new flash.geom.ColorTransform(1,_loc12_,0,1,0,0,0,100);
  68.       }
  69.       var _loc9_ = this.ct;
  70.       var _loc8_ = "normal";
  71.       var _loc10_ = null;
  72.       var _loc11_ = true;
  73.       this.bmpCanvas.draw(_loc2_,_loc3_,_loc9_,_loc8_,_loc10_,_loc11_);
  74.    }
  75.    function checkCollision(Void)
  76.    {
  77.       var _loc3_ = this.screenPos.x;
  78.       var _loc2_ = Game.screenH - (this.screenPos.y - 10);
  79.       return Game.bmpDead.hitTest(new flash.geom.Point(0,0),250,new flash.geom.Point(_loc3_,_loc2_));
  80.    }
  81. }
  82.