home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Classicos / smashout.swf / scripts / __Packages / GDK / Base.as next >
Encoding:
Text File  |  2005-11-09  |  3.1 KB  |  141 lines

  1. class GDK.Base extends MovieClip
  2. {
  3.    var worlds;
  4.    var useMask;
  5.    var onResize;
  6.    var mcMask;
  7.    var engineIntervalID;
  8.    var lastUpdate;
  9.    var onStart;
  10.    var onPause;
  11.    var onResume;
  12.    var onStop;
  13.    var activeWorld;
  14.    var onUpdate;
  15.    var paused = false;
  16.    var width = 100;
  17.    var height = 100;
  18.    var version = "GDK 1,1,10,0";
  19.    function Base()
  20.    {
  21.       super();
  22.       this.worlds = new GDK.Collection();
  23.       if(this.useMask)
  24.       {
  25.          this.setMask(this.attachMovie("Square","mcMask",13421568));
  26.       }
  27.       this.setSize(Math.round(this._xscale),Math.round(this._yscale));
  28.       this._yscale = this._xscale = 100;
  29.       for(var _loc3_ in this)
  30.       {
  31.          if(_loc3_.indexOf("mcDead") != -1)
  32.          {
  33.             this[_loc3_].swapDepths(1048575);
  34.             this[_loc3_].removeMovieClip();
  35.          }
  36.       }
  37.    }
  38.    function setSize(w, h, noEvent)
  39.    {
  40.       if(w == this.width && h == this.height)
  41.       {
  42.          return undefined;
  43.       }
  44.       if(noEvent)
  45.       {
  46.          this.width = w;
  47.          this.height = h;
  48.       }
  49.       else
  50.       {
  51.          this.onResize(this.width = w,this.height = h,this.width,this.height);
  52.       }
  53.       if(this.useMask)
  54.       {
  55.          this.mcMask._xscale = w;
  56.          this.mcMask._yscale = h;
  57.       }
  58.    }
  59.    function start()
  60.    {
  61.       if(this.engineIntervalID)
  62.       {
  63.          return undefined;
  64.       }
  65.       this.lastUpdate = getTimer();
  66.       this.engineIntervalID = setInterval(this,"update",0);
  67.       this.onStart();
  68.       this.update();
  69.    }
  70.    function pause()
  71.    {
  72.       this.paused = true;
  73.       this.onPause();
  74.       this.update();
  75.    }
  76.    function resume()
  77.    {
  78.       this.paused = false;
  79.       this.onResume();
  80.       this.update();
  81.    }
  82.    function stop()
  83.    {
  84.       this.onStop();
  85.       clearInterval(this.engineIntervalID);
  86.       delete this.engineIntervalID;
  87.    }
  88.    function update()
  89.    {
  90.       var _loc2_ = undefined;
  91.       if(this.paused)
  92.       {
  93.          this.lastUpdate = getTimer();
  94.          return undefined;
  95.       }
  96.       this.activeWorld.update(_loc2_ = (this.lastUpdate - (this.lastUpdate = getTimer())) * -0.001);
  97.       this.onUpdate(_loc2_);
  98.    }
  99.    function addWorld(worldObj)
  100.    {
  101.       if(!this.worlds.addMember(worldObj))
  102.       {
  103.          return undefined;
  104.       }
  105.       worldObj.displayNode = this;
  106.       worldObj.engine = this;
  107.    }
  108.    function removeWorld(worldObj)
  109.    {
  110.       if(!this.worlds[worldObj])
  111.       {
  112.          return undefined;
  113.       }
  114.       var _loc2_ = this.worlds.length;
  115.       while((_loc2_ = _loc2_ - 1) > -1)
  116.       {
  117.          if(this.worlds[_loc2_] == worldObj)
  118.          {
  119.             this.worlds.splice(_loc2_,1);
  120.          }
  121.       }
  122.       delete this.worlds[worldObj];
  123.       worldObj.removeFromScene();
  124.    }
  125.    function setActiveWorld(worldObj)
  126.    {
  127.       if(this.activeWorld == worldObj)
  128.       {
  129.          return undefined;
  130.       }
  131.       this.activeWorld.removeFromScene();
  132.       this.activeWorld = worldObj;
  133.       worldObj.addToScene();
  134.    }
  135.    function onUnload()
  136.    {
  137.       this.stop();
  138.       this.setActiveWorld(null);
  139.    }
  140. }
  141.