home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / filler.swf / scripts / org / cove / ape / AbstractCollection.as next >
Encoding:
Text File  |  2008-09-02  |  8.6 KB  |  312 lines

  1. package org.cove.ape
  2. {
  3.    import flash.display.Sprite;
  4.    import flash.utils.getQualifiedClassName;
  5.    
  6.    public class AbstractCollection
  7.    {
  8.        
  9.       
  10.       private var _sprite:Sprite;
  11.       
  12.       private var _isParented:Boolean;
  13.       
  14.       private var _particles:Array;
  15.       
  16.       private var _constraints:Array;
  17.       
  18.       public function AbstractCollection()
  19.       {
  20.          super();
  21.          if(getQualifiedClassName(this) == "org.cove.ape::AbstractCollection")
  22.          {
  23.             throw new ArgumentError("AbstractCollection can\'t be instantiated directly");
  24.          }
  25.          _isParented = false;
  26.          _particles = new Array();
  27.          _constraints = new Array();
  28.       }
  29.       
  30.       public function getAll() : Array
  31.       {
  32.          return particles.concat(constraints);
  33.       }
  34.       
  35.       internal function checkCollisionsVsCollection(param1:AbstractCollection) : void
  36.       {
  37.          var _loc2_:int = 0;
  38.          var _loc3_:int = 0;
  39.          var _loc4_:int = 0;
  40.          var _loc5_:AbstractParticle = null;
  41.          var _loc6_:int = 0;
  42.          var _loc7_:int = 0;
  43.          var _loc8_:int = 0;
  44.          var _loc9_:AbstractParticle = null;
  45.          var _loc10_:SpringConstraint = null;
  46.          var _loc11_:SpringConstraint = null;
  47.          var _loc12_:int = 0;
  48.          _loc2_ = int(_particles.length);
  49.          _loc3_ = 0;
  50.          while(_loc3_ < _loc2_)
  51.          {
  52.             if((_loc5_ = _particles[_loc3_]).collidable)
  53.             {
  54.                _loc6_ = int(param1.particles.length);
  55.                _loc7_ = 0;
  56.                while(_loc7_ < _loc6_)
  57.                {
  58.                   if((_loc9_ = param1.particles[_loc7_]).collidable)
  59.                   {
  60.                      CollisionDetector.test(_loc5_,_loc9_);
  61.                   }
  62.                   _loc7_++;
  63.                }
  64.                _loc8_ = int(param1.constraints.length);
  65.                _loc7_ = 0;
  66.                while(_loc7_ < _loc8_)
  67.                {
  68.                   if((_loc10_ = param1.constraints[_loc7_]).collidable && !_loc10_.isConnectedTo(_loc5_))
  69.                   {
  70.                      _loc10_.scp.updatePosition();
  71.                      CollisionDetector.test(_loc5_,_loc10_.scp);
  72.                   }
  73.                   _loc7_++;
  74.                }
  75.             }
  76.             _loc3_++;
  77.          }
  78.          _loc4_ = int(_constraints.length);
  79.          _loc3_ = 0;
  80.          while(_loc3_ < _loc4_)
  81.          {
  82.             if((_loc11_ = _constraints[_loc3_]).collidable)
  83.             {
  84.                _loc6_ = int(param1.particles.length);
  85.                _loc12_ = 0;
  86.                while(_loc12_ < _loc6_)
  87.                {
  88.                   if((_loc9_ = param1.particles[_loc12_]).collidable && !_loc11_.isConnectedTo(_loc9_))
  89.                   {
  90.                      _loc11_.scp.updatePosition();
  91.                      CollisionDetector.test(_loc9_,_loc11_.scp);
  92.                   }
  93.                   _loc12_++;
  94.                }
  95.             }
  96.             _loc3_++;
  97.          }
  98.       }
  99.       
  100.       public function get sprite() : Sprite
  101.       {
  102.          if(_sprite != null)
  103.          {
  104.             return _sprite;
  105.          }
  106.          if(APEngine.container == null)
  107.          {
  108.             throw new Error("The container property of the APEngine class has not been set");
  109.          }
  110.          _sprite = new Sprite();
  111.          APEngine.container.addChild(_sprite);
  112.          return _sprite;
  113.       }
  114.       
  115.       internal function checkInternalCollisions() : void
  116.       {
  117.          var _loc1_:int = 0;
  118.          var _loc2_:int = 0;
  119.          var _loc3_:AbstractParticle = null;
  120.          var _loc4_:int = 0;
  121.          var _loc5_:int = 0;
  122.          var _loc6_:int = 0;
  123.          var _loc7_:AbstractParticle = null;
  124.          var _loc8_:SpringConstraint = null;
  125.          _loc1_ = int(_particles.length);
  126.          _loc2_ = 0;
  127.          while(_loc2_ < _loc1_)
  128.          {
  129.             _loc3_ = _particles[_loc2_];
  130.             if(_loc3_.collidable)
  131.             {
  132.                _loc4_ = _loc2_ + 1;
  133.                while(_loc4_ < _loc1_)
  134.                {
  135.                   if((_loc7_ = _particles[_loc4_]).collidable)
  136.                   {
  137.                      CollisionDetector.test(_loc3_,_loc7_);
  138.                   }
  139.                   _loc4_++;
  140.                }
  141.                _loc5_ = int(_constraints.length);
  142.                _loc6_ = 0;
  143.                while(_loc6_ < _loc5_)
  144.                {
  145.                   if((_loc8_ = _constraints[_loc6_]).collidable && !_loc8_.isConnectedTo(_loc3_))
  146.                   {
  147.                      _loc8_.scp.updatePosition();
  148.                      CollisionDetector.test(_loc3_,_loc8_.scp);
  149.                   }
  150.                   _loc6_++;
  151.                }
  152.             }
  153.             _loc2_++;
  154.          }
  155.       }
  156.       
  157.       public function addParticle(param1:AbstractParticle) : void
  158.       {
  159.          particles.push(param1);
  160.          if(isParented)
  161.          {
  162.             param1.init();
  163.          }
  164.       }
  165.       
  166.       public function removeConstraint(param1:AbstractConstraint) : void
  167.       {
  168.          var _loc2_:int = 0;
  169.          _loc2_ = constraints.indexOf(param1);
  170.          if(_loc2_ == -1)
  171.          {
  172.             return;
  173.          }
  174.          constraints.splice(_loc2_,1);
  175.          param1.cleanup();
  176.       }
  177.       
  178.       internal function get isParented() : Boolean
  179.       {
  180.          return _isParented;
  181.       }
  182.       
  183.       public function init() : void
  184.       {
  185.          var _loc1_:int = 0;
  186.          _loc1_ = 0;
  187.          while(_loc1_ < particles.length)
  188.          {
  189.             particles[_loc1_].init();
  190.             _loc1_++;
  191.          }
  192.          _loc1_ = 0;
  193.          while(_loc1_ < constraints.length)
  194.          {
  195.             constraints[_loc1_].init();
  196.             _loc1_++;
  197.          }
  198.       }
  199.       
  200.       internal function satisfyConstraints() : void
  201.       {
  202.          var _loc1_:int = 0;
  203.          var _loc2_:int = 0;
  204.          var _loc3_:AbstractConstraint = null;
  205.          _loc1_ = int(_constraints.length);
  206.          _loc2_ = 0;
  207.          while(_loc2_ < _loc1_)
  208.          {
  209.             _loc3_ = _constraints[_loc2_];
  210.             _loc3_.resolve();
  211.             _loc2_++;
  212.          }
  213.       }
  214.       
  215.       public function paint() : void
  216.       {
  217.          var _loc1_:AbstractParticle = null;
  218.          var _loc2_:int = 0;
  219.          var _loc3_:int = 0;
  220.          var _loc4_:SpringConstraint = null;
  221.          _loc2_ = int(_particles.length);
  222.          _loc3_ = 0;
  223.          while(_loc3_ < _loc2_)
  224.          {
  225.             _loc1_ = _particles[_loc3_];
  226.             if(!_loc1_.fixed || _loc1_.alwaysRepaint)
  227.             {
  228.                _loc1_.paint();
  229.             }
  230.             _loc3_++;
  231.          }
  232.          _loc2_ = int(_constraints.length);
  233.          _loc3_ = 0;
  234.          while(_loc3_ < _loc2_)
  235.          {
  236.             if(!(_loc4_ = _constraints[_loc3_]).fixed || _loc4_.alwaysRepaint)
  237.             {
  238.                _loc4_.paint();
  239.             }
  240.             _loc3_++;
  241.          }
  242.       }
  243.       
  244.       public function addConstraint(param1:AbstractConstraint) : void
  245.       {
  246.          constraints.push(param1);
  247.          if(isParented)
  248.          {
  249.             param1.init();
  250.          }
  251.       }
  252.       
  253.       internal function set isParented(param1:Boolean) : void
  254.       {
  255.          _isParented = param1;
  256.       }
  257.       
  258.       public function removeParticle(param1:AbstractParticle) : void
  259.       {
  260.          var _loc2_:int = 0;
  261.          _loc2_ = particles.indexOf(param1);
  262.          if(_loc2_ == -1)
  263.          {
  264.             return;
  265.          }
  266.          particles.splice(_loc2_,1);
  267.          param1.cleanup();
  268.       }
  269.       
  270.       public function cleanup() : void
  271.       {
  272.          var _loc1_:int = 0;
  273.          _loc1_ = 0;
  274.          while(_loc1_ < particles.length)
  275.          {
  276.             particles[_loc1_].cleanup();
  277.             _loc1_++;
  278.          }
  279.          _loc1_ = 0;
  280.          while(_loc1_ < constraints.length)
  281.          {
  282.             constraints[_loc1_].cleanup();
  283.             _loc1_++;
  284.          }
  285.       }
  286.       
  287.       public function get particles() : Array
  288.       {
  289.          return _particles;
  290.       }
  291.       
  292.       internal function integrate(param1:Number) : void
  293.       {
  294.          var _loc2_:int = 0;
  295.          var _loc3_:int = 0;
  296.          var _loc4_:AbstractParticle = null;
  297.          _loc2_ = int(_particles.length);
  298.          _loc3_ = 0;
  299.          while(_loc3_ < _loc2_)
  300.          {
  301.             (_loc4_ = _particles[_loc3_]).update(param1);
  302.             _loc3_++;
  303.          }
  304.       }
  305.       
  306.       public function get constraints() : Array
  307.       {
  308.          return _constraints;
  309.       }
  310.    }
  311. }
  312.