home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Classicos / smashout.swf / scripts / __Packages / GDK / World.as < prev   
Encoding:
Text File  |  2005-11-09  |  4.0 KB  |  164 lines

  1. class GDK.World extends GDK.Generic
  2. {
  3.    var children;
  4.    var objects;
  5.    var updateList;
  6.    var displayQueue;
  7.    var activeObjects;
  8.    var name;
  9.    var viewport;
  10.    var world;
  11.    var target;
  12.    var engine;
  13.    var onUpdate;
  14.    static var worldsCreated = -1;
  15.    var useDefaultCamera = true;
  16.    var className = "World";
  17.    var isDisplayNode = true;
  18.    var renderable = true;
  19.    var affectChildren = false;
  20.    var objectsAdded = 0;
  21.    function World(name, viewPort)
  22.    {
  23.       super();
  24.       this.uniqueID = ++GDK.World.worldsCreated;
  25.       this.children = null;
  26.       this.objects = [];
  27.       this.updateList = new GDK.Collection();
  28.       this.displayQueue = [];
  29.       this.activeObjects = new GDK.Collection();
  30.       this.name = name == null ? "World " + this.uniqueID : name;
  31.       if(this.viewport)
  32.       {
  33.          this.addObject(this.viewport);
  34.       }
  35.       else if(this.useDefaultCamera)
  36.       {
  37.          this.addObject(this.viewport = new GDK.Camera());
  38.       }
  39.       this.world = this;
  40.    }
  41.    function addActiveObject(obj)
  42.    {
  43.       return this.activeObjects.addMember(obj);
  44.    }
  45.    function removeActiveObject(obj)
  46.    {
  47.       if(!obj.__a)
  48.       {
  49.          return undefined;
  50.       }
  51.       delete obj.__a;
  52.       var _loc2_ = this.activeObjects.length;
  53.       while((_loc2_ = _loc2_ - 1) > -1)
  54.       {
  55.          if(this.activeObjects[_loc2_] == obj)
  56.          {
  57.             this.activeObjects.splice(_loc2_,1);
  58.             return undefined;
  59.          }
  60.       }
  61.    }
  62.    function addToUpdateList(obj)
  63.    {
  64.       return this.updateList.addMember(obj);
  65.    }
  66.    function removeFromUpdateList(obj)
  67.    {
  68.       return this.updateList.removeMember(obj);
  69.    }
  70.    function sendUpdates(elapsed)
  71.    {
  72.       this.updateList.update(elapsed);
  73.    }
  74.    function render(elapsed)
  75.    {
  76.       var _loc2_ = undefined;
  77.       if(!(_loc2_ = this.displayQueue.length))
  78.       {
  79.          return undefined;
  80.       }
  81.       while((_loc2_ = _loc2_ - 1) > -1)
  82.       {
  83.          this.displayQueue[_loc2_].setDisplay(elapsed);
  84.          delete this.displayQueue[_loc2_].queueForDisplay;
  85.       }
  86.       this.displayQueue = [];
  87.       updateAfterEvent();
  88.    }
  89.    function centerViewport(vertical, horizontal)
  90.    {
  91.       this.viewport.halfWidth = this.target._x = (this.viewport.screenWidth = this.engine.width) * 0.5;
  92.       this.viewport.halfHeight = this.target._y = (this.viewport.screenHeight = this.engine.height) * 0.5;
  93.    }
  94.    function queueForDisplay(obj)
  95.    {
  96.       if(!obj.queueForDisplay)
  97.       {
  98.          return undefined;
  99.       }
  100.       obj.queueForDisplay = null;
  101.       this.displayQueue.push(obj);
  102.    }
  103.    function update(elapsed)
  104.    {
  105.       this.sendUpdates(elapsed);
  106.       this.onUpdate(elapsed);
  107.       this.render(elapsed);
  108.    }
  109.    function addObject(obj, isolated)
  110.    {
  111.       if(obj.world == this)
  112.       {
  113.          return false;
  114.       }
  115.       if(obj.world)
  116.       {
  117.          obj.world.removeObject(obj);
  118.       }
  119.       this.objects.push(obj);
  120.       obj.world = this;
  121.       obj.uniqueID = this.objectsAdded++;
  122.       if(obj.children.length)
  123.       {
  124.          var _loc3_ = obj.children.length;
  125.          while((_loc3_ = _loc3_ - 1) > -1)
  126.          {
  127.             this.addObject(obj.children[_loc3_],true);
  128.          }
  129.       }
  130.       if(!isolated)
  131.       {
  132.          this.addChild(obj,true);
  133.       }
  134.       obj.positionChanged(0,0,0);
  135.       obj.onAddToWorld();
  136.       return true;
  137.    }
  138.    function removeObject(obj)
  139.    {
  140.       obj.removeFromScene();
  141.       this.removeChild(obj);
  142.       var _loc2_ = this.objects.length;
  143.       while((_loc2_ = _loc2_ - 1) > -1)
  144.       {
  145.          if(this.objects[_loc2_] == obj)
  146.          {
  147.             this.objects.splice(_loc2_,1);
  148.             break;
  149.          }
  150.       }
  151.       GDK.Collection.removeFromAll(obj);
  152.       this.removeFromUpdateList(obj);
  153.       obj.onRemoveFromWorld();
  154.    }
  155.    function addChild(obj, isolated)
  156.    {
  157.       super.addChild(obj,true);
  158.    }
  159.    function timelineUpdate(elapsed)
  160.    {
  161.       this.render(elapsed);
  162.    }
  163. }
  164.