home *** CD-ROM | disk | FTP | other *** search
/ Champak 48 / cdrom_image.iso / Games / bobsleddin.swf / scripts / __Packages / FlyingCargo.as < prev    next >
Encoding:
Text File  |  2007-09-28  |  3.2 KB  |  110 lines

  1. class FlyingCargo extends GenericObject
  2. {
  3.    var world;
  4.    var target;
  5.    var linkageID = "Flying Bird";
  6.    var inMotion = true;
  7.    var fixedToCourse = true;
  8.    var offsetX = 0;
  9.    var offsetY = 0;
  10.    var offsetZ = 0;
  11.    var depthGroup = 2;
  12.    var cullDistance = 6000;
  13.    var time = 0;
  14.    var dist = 0;
  15.    function FlyingCargo(watch)
  16.    {
  17.       super();
  18.       this.watch = watch;
  19.    }
  20.    function onAddToWorld()
  21.    {
  22.       this.world.registerForUpdates(this);
  23.    }
  24.    function onAddToScene()
  25.    {
  26.    }
  27.    function onRemoveFromScene()
  28.    {
  29.       this.world.removeFromUpdates(this);
  30.       this.world.removeObject(this);
  31.    }
  32.    function followCourse(elapsed, move)
  33.    {
  34.       var _loc5_ = this.sector;
  35.       var _loc3_ = new Vector(this.x - this.offsetX,this.y - this.offsetY,this.z - this.offsetZ);
  36.       while(move > 0)
  37.       {
  38.          var _loc4_ = new Vector(_loc5_.x - this.x,_loc5_.y - this.y,_loc5_.z - this.z);
  39.          var _loc6_ = _loc4_.length;
  40.          if(_loc6_ > move)
  41.          {
  42.             _loc3_.x += this.sector.direction.x * move;
  43.             _loc3_.y += this.sector.direction.y * move;
  44.             _loc3_.z += this.sector.direction.z * move;
  45.             move = 0;
  46.          }
  47.          else
  48.          {
  49.             _loc3_.x += _loc4_.x;
  50.             _loc3_.y += _loc4_.y;
  51.             _loc3_.z += _loc4_.z;
  52.             _loc5_ = _loc5_.next;
  53.             move -= _loc6_;
  54.          }
  55.       }
  56.       this.x = _loc3_.x + this.offsetX;
  57.       this.y = _loc3_.y + this.offsetY;
  58.       this.z = _loc3_.z + this.offsetZ;
  59.    }
  60.    function dropCargo()
  61.    {
  62.       this.target.cargo._visible = false;
  63.       var _loc2_ = this.sector;
  64.       var _loc3_ = 0;
  65.       var _loc5_ = 0;
  66.       while(_loc5_ < 10)
  67.       {
  68.          var _loc4_ = new GamePoint(GamePoint.HIGH_VALUE);
  69.          this.world.addObject(_loc4_,_loc2_.previous.x + _loc2_.direction.x * _loc3_,_loc2_.previous.y + _loc2_.radius - 25 + _loc2_.direction.y * _loc3_,_loc2_.previous.z + _loc2_.direction.z * _loc3_,_loc2_.index);
  70.          _loc4_.addToScene();
  71.          _loc3_ += 200;
  72.          if(_loc3_ > _loc2_.length)
  73.          {
  74.             _loc3_ %= _loc2_.length;
  75.             _loc2_ = _loc2_.next;
  76.          }
  77.          _loc5_ = _loc5_ + 1;
  78.       }
  79.       this.fixedToCourse = false;
  80.       this.offsetX = !random(2) ? -100 : 100;
  81.    }
  82.    function onUpdate(elapsed)
  83.    {
  84.       this.time += elapsed;
  85.       var _loc3_ = (this.watch.currentSpeed + 400) * elapsed;
  86.       if(this.fixedToCourse)
  87.       {
  88.          this.y += - this.offsetY + (this.offsetY -= 40 * elapsed);
  89.          this.followCourse(elapsed,_loc3_);
  90.          if(this.z > this.watch.z + 1000)
  91.          {
  92.             this.dropCargo();
  93.          }
  94.       }
  95.       else
  96.       {
  97.          this.x += - this.offsetX + (this.offsetX += this.offsetX * elapsed);
  98.          this.y += - this.offsetY + (this.offsetY -= 400 * elapsed);
  99.          this.z += (1000 - Math.abs(this.offsetX * 0.1) - Math.abs(this.offsetY * 0.1)) * elapsed;
  100.          this.target._rotation += ((this.offsetX <= 0 ? -45 : 45) - this.target._rotation) * elapsed;
  101.       }
  102.       if(this.z > this.world.camera.z + this.world.camera.hither)
  103.       {
  104.          this.addToScene();
  105.       }
  106.       this.checkSectorLocation();
  107.       this.updateDepth();
  108.    }
  109. }
  110.