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

  1. class GenericObject extends BB
  2. {
  3.    var linkageID;
  4.    var target;
  5.    var world;
  6.    var onAddToScene;
  7.    var onRemoveFromScene;
  8.    var onChanged;
  9.    var screenX;
  10.    var screenY;
  11.    var onDisplay;
  12.    var objectSoundID;
  13.    var done;
  14.    var length;
  15.    var duration;
  16.    var sector = 0;
  17.    var trackInSectorGrid = true;
  18.    var uniqueID = 0;
  19.    var generatorDisplacement = 0;
  20.    var sounds = {};
  21.    var x = 0;
  22.    var y = 0;
  23.    var z = 0;
  24.    var radius = 50;
  25.    var inScene = false;
  26.    var useMinScale = false;
  27.    var minScreenScale = 10;
  28.    var renderable = true;
  29.    var assetRotation = 0;
  30.    var useRotation = true;
  31.    var cullDistance = 3000;
  32.    var collisionGroup = 0;
  33.    var depthGroup = 1;
  34.    static var soundsCreated = 0;
  35.    function GenericObject()
  36.    {
  37.       super();
  38.    }
  39.    function update()
  40.    {
  41.    }
  42.    function addToScene()
  43.    {
  44.       if(this.inScene || !this.renderable)
  45.       {
  46.          return undefined;
  47.       }
  48.       if(this.linkageID != null)
  49.       {
  50.          this.target = this.world.display.attachMovie(this.linkageID,"O" + this.uniqueID,0);
  51.       }
  52.       else
  53.       {
  54.          this.target = this.world.display.createEmptyMovieClip("O" + this.uniqueID,0);
  55.       }
  56.       this.target.owner = this;
  57.       this.updateDepth();
  58.       if(this.useRotation)
  59.       {
  60.          this.target._rotation = this.assetRotation;
  61.       }
  62.       this.inScene = true;
  63.       this.onAddToScene();
  64.    }
  65.    function removeFromScene()
  66.    {
  67.       if(!this.inScene)
  68.       {
  69.          return undefined;
  70.       }
  71.       this.inScene = false;
  72.       this.onRemoveFromScene();
  73.       this.target.swapDepths(1048575);
  74.       this.target.removeMovieClip();
  75.    }
  76.    function checkSectorLocation()
  77.    {
  78.       if(this.z > this.sector.z && this.sector.next)
  79.       {
  80.          this.sector.removeObject(this);
  81.          while(this.sector = this.sector.next)
  82.          {
  83.             if(this.z <= this.sector.z)
  84.             {
  85.                break;
  86.             }
  87.          }
  88.          this.sector.addObject(this);
  89.       }
  90.       else if(this.sector.previous && this.z <= this.sector.previous.z)
  91.       {
  92.          this.sector.removeObject(this);
  93.          while(this.sector = this.sector.previous)
  94.          {
  95.             if(this.z > this.sector.previous.z)
  96.             {
  97.                break;
  98.             }
  99.          }
  100.          this.sector.addObject(this);
  101.       }
  102.    }
  103.    function moveTo(x, y, z)
  104.    {
  105.       if(x == this.x && y == this.y && z == this.z)
  106.       {
  107.          return undefined;
  108.       }
  109.       this.x = x;
  110.       this.y = y;
  111.       this.z = z;
  112.       this.checkSectorLocation();
  113.       this.updateDepth();
  114.       this.onChanged();
  115.    }
  116.    function moveBy(x, y, z)
  117.    {
  118.       if(x || y || z)
  119.       {
  120.          this.x += x;
  121.          this.y += y;
  122.          this.z += z;
  123.          this.checkSectorLocation();
  124.          this.updateDepth();
  125.          this.onChanged();
  126.       }
  127.    }
  128.    function setAssetRotation(angle)
  129.    {
  130.       this.target._rotation = this.assetRotation = angle;
  131.    }
  132.    function setDisplay(offsetX, offsetY, offsetZ, depthRatio)
  133.    {
  134.       if(!this.renderable)
  135.       {
  136.          return undefined;
  137.       }
  138.       this.screenX = this.target._x = offsetX * depthRatio;
  139.       this.screenY = this.target._y = offsetY * depthRatio;
  140.       this.target._xscale = this.target._yscale = !this.useMinScale ? depthRatio * 100 : Math.max(depthRatio * 100,this.minScreenScale);
  141.       this.onDisplay(offsetX,offsetY,offsetZ,depthRatio);
  142.    }
  143.    function attachSound(soundID, altTarget)
  144.    {
  145.       var _loc2_ = new Sound(!altTarget ? this.target : altTarget);
  146.       _loc2_.attachSound(soundID);
  147.       return _loc2_;
  148.    }
  149.    function setObjectSound(linkageID, altTarget)
  150.    {
  151.       this.objectSoundID = linkageID;
  152.       if(this.sounds[linkageID])
  153.       {
  154.          return undefined;
  155.       }
  156.       var _loc0_ = null;
  157.       var _loc3_ = this.sounds[linkageID] = this.attachSound(linkageID,_root);
  158.       _loc3_.done = true;
  159.       _loc3_.onSoundComplete = function()
  160.       {
  161.          this.done = true;
  162.          this.length = this.duration;
  163.       };
  164.    }
  165.    function playObjectSound()
  166.    {
  167.       var _loc2_ = this.sounds[this.objectSoundID];
  168.       var _loc3_ = _loc2_.position;
  169.       if(_loc2_.done || _loc2_.lastKnownTime != _loc3_ || _loc3_ == 0 || _loc2_.lastPlayAt + _loc2_.duration < getTimer())
  170.       {
  171.          _loc2_.lastKnownTime = _loc3_;
  172.          _loc2_.lastPlayAt = getTimer();
  173.          _loc2_.start();
  174.          _loc2_.done = false;
  175.       }
  176.    }
  177.    function toString()
  178.    {
  179.       return "Generic Object";
  180.    }
  181. }
  182.