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

  1. class Vehicle
  2. {
  3.    var index;
  4.    var position;
  5.    var aDropZones;
  6.    var bmpCanvas;
  7.    var bmpVehicle;
  8.    var width;
  9.    var height;
  10.    var bDestroyed;
  11.    var mode;
  12.    var frameExp;
  13.    var bTaken;
  14.    var vel;
  15.    var screenPos;
  16.    var bOnScreen;
  17.    var sType = "vehicle";
  18.    static var maxDist = 10;
  19.    var weightFactor = 3;
  20.    var angle = 0;
  21.    function Vehicle(posNew, id, aDropZonesNew, indexNew)
  22.    {
  23.       this.index = indexNew;
  24.       this.position = posNew.clone();
  25.       this.aDropZones = aDropZonesNew;
  26.       this.bmpCanvas = Game.bmpShots;
  27.       this.bmpVehicle = flash.display.BitmapData.loadBitmap("vehicle " + id);
  28.       this.width = this.bmpVehicle.width;
  29.       this.height = this.bmpVehicle.height;
  30.       this.bDestroyed = false;
  31.       this.mode = 0;
  32.       this.frameExp = 0;
  33.       this.bTaken = false;
  34.       this.vel = new flash.geom.Point(0,0);
  35.    }
  36.    function step(refRope)
  37.    {
  38.       if(this.mode == 0)
  39.       {
  40.          var _loc6_ = refRope.endPos.x - this.position.x;
  41.          var _loc5_ = refRope.endPos.y - this.position.y;
  42.          if(Math.abs(_loc5_) < 10 && Math.abs(_loc6_) < 10 && !refRope.bHasCargo)
  43.          {
  44.             this.mode = 1;
  45.             refRope.refCargo = this;
  46.             refRope.bHasCargo = true;
  47.             Game.getInstance().mcAlert.gotoAndPlay("show2");
  48.          }
  49.       }
  50.       else if(this.mode == 1)
  51.       {
  52.          this.position.x = refRope.endPos.x;
  53.          this.position.y = refRope.endPos.y;
  54.          if(this.checkPlatform())
  55.          {
  56.             Game.getInstance().saveVehicleInd(this.index);
  57.             Game.getInstance().checkIfCompleted();
  58.             this.mode = null;
  59.             refRope.refCargo = null;
  60.             refRope.bHasCargo = false;
  61.          }
  62.          else
  63.          {
  64.             var _loc7_ = this.checkCollision();
  65.             if((_loc7_ || this.position.y < 41) && this.bTaken)
  66.             {
  67.                this.die();
  68.             }
  69.             else if(!this.bTaken && this.position.y > 44)
  70.             {
  71.                this.bTaken = true;
  72.             }
  73.          }
  74.       }
  75.       else if(this.mode == 2)
  76.       {
  77.          this.vel.y -= 0.5;
  78.          this.vel.x *= 0.98;
  79.          this.vel.y *= 0.98;
  80.          this.position.x += this.vel.x;
  81.          this.position.y += this.vel.y;
  82.          var _loc3_ = 0;
  83.          while(_loc3_ < this.aDropZones.length)
  84.          {
  85.             var _loc2_ = this.aDropZones[_loc3_];
  86.             if(this.position.x - this.width / 2 > _loc2_.plaPos.x && this.position.x + this.width / 2 < _loc2_.plaPos.x + _loc2_.plaWidth && this.position.y - _loc2_.plaPos.y < this.height / 2 + 2)
  87.             {
  88.                this.position.y = _loc2_.plaPos.y + this.height / 2;
  89.                if(Math.abs(this.vel.y) < 0.5)
  90.                {
  91.                   Game.getInstance().saveVehicleInd(this.index);
  92.                   Game.getInstance().checkIfCompleted();
  93.                   this.mode = null;
  94.                }
  95.                this.vel.x = 0;
  96.                this.vel.y = Math.abs(this.vel.y) * 0.7;
  97.             }
  98.             else if(this.checkCollision() || this.position.y < 40)
  99.             {
  100.                this.die();
  101.             }
  102.             _loc3_ = _loc3_ + 1;
  103.          }
  104.       }
  105.    }
  106.    function draw(leftEdge)
  107.    {
  108.       var _loc2_ = this.position.x - leftEdge - this.width / 2;
  109.       var _loc5_ = this.position.y + this.height / 2;
  110.       this.screenPos = new flash.geom.Point(_loc2_,_loc5_);
  111.       if(!this.bDestroyed)
  112.       {
  113.          if(_loc2_ > - this.width && _loc2_ < Game.screenW + this.width)
  114.          {
  115.             this.bOnScreen = true;
  116.             if(this.mode == 0)
  117.             {
  118.                var _loc3_ = Math.sin(this.angle) + 1;
  119.                this.angle += 0.6;
  120.                var _loc6_ = new flash.display.BitmapData(this.width + 10,this.height + 10,true,0);
  121.                var _loc9_ = 16777215;
  122.                var _loc15_ = 0.4 + 0.4 * _loc3_;
  123.                var _loc12_ = 3 + 4 * _loc3_;
  124.                var _loc11_ = 3 + 4 * _loc3_;
  125.                var _loc13_ = 4 + 4 * _loc3_;
  126.                var _loc7_ = 1;
  127.                var _loc10_ = false;
  128.                var _loc14_ = false;
  129.                var _loc8_ = new flash.filters.GlowFilter(_loc9_,_loc15_,_loc12_,_loc11_,_loc13_,_loc7_,_loc10_,_loc14_);
  130.                _loc6_.applyFilter(this.bmpVehicle,this.bmpVehicle.rectangle,new flash.geom.Point(5,5),_loc8_);
  131.                var _loc4_ = new flash.geom.Matrix();
  132.                _loc4_.translate(this.screenPos.x + 5,Game.screenH - this.screenPos.y - 5);
  133.                this.bmpCanvas.draw(_loc6_,_loc4_,null,null,null,true);
  134.             }
  135.             else
  136.             {
  137.                this.bmpCanvas.copyPixels(this.bmpVehicle,this.bmpVehicle.rectangle,new flash.geom.Point(_loc2_,Game.screenH - _loc5_),null,null,true);
  138.             }
  139.          }
  140.       }
  141.       else
  142.       {
  143.          this.drawExplosion(new flash.geom.Point(this.position.x - leftEdge,this.position.y),true);
  144.       }
  145.       if(this.mode == null && (_loc2_ < - this.width || _loc2_ > Game.screenW + this.width))
  146.       {
  147.          Game.getInstance().removeVehicle(this);
  148.       }
  149.    }
  150.    function die(Void)
  151.    {
  152.       this.mode = null;
  153.       this.bDestroyed = true;
  154.       Sounds.playSound("bazooka");
  155.    }
  156.    function drawExplosion(pos, bRemove)
  157.    {
  158.       var _loc3_ = _root.attachMovie("explosion2","mcExp",_root.getNextHighestDepth());
  159.       _loc3_.gotoAndStop(this.frameExp + 1);
  160.       var _loc4_ = new flash.geom.Matrix();
  161.       _loc4_.translate(pos.x,Game.screenH - pos.y);
  162.       this.bmpCanvas.draw(_loc3_,_loc4_,null,null,null,true);
  163.       _loc3_.removeMovieClip();
  164.       this.frameExp = this.frameExp + 1;
  165.       if(this.frameExp == 27)
  166.       {
  167.          if(bRemove)
  168.          {
  169.             this.onEndDeadAnim();
  170.          }
  171.       }
  172.    }
  173.    function onEndDeadAnim(Void)
  174.    {
  175.       Game.getInstance().onLooseLife();
  176.    }
  177.    function checkCollision(Void)
  178.    {
  179.       var _loc3_ = - this.screenPos.x;
  180.       var _loc2_ = - (Game.screenH - this.screenPos.y);
  181.       return Game.bmpDead.hitTest(new flash.geom.Point(_loc3_,_loc2_),250,this.bmpVehicle,new flash.geom.Point(0,0),250);
  182.    }
  183.    function checkPlatform(Void)
  184.    {
  185.       var _loc3_ = 0;
  186.       while(_loc3_ < this.aDropZones.length)
  187.       {
  188.          var _loc2_ = this.aDropZones[_loc3_];
  189.          if(this.position.x - this.width / 2 > _loc2_.plaPos.x && this.position.x + this.width / 2 < _loc2_.plaPos.x + _loc2_.plaWidth && this.position.y - _loc2_.plaPos.y < this.height / 2 + 2)
  190.          {
  191.             this.position.y = _loc2_.plaPos.y + this.height / 2;
  192.             return true;
  193.          }
  194.          _loc3_ = _loc3_ + 1;
  195.       }
  196.       return false;
  197.    }
  198. }
  199.