home *** CD-ROM | disk | FTP | other *** search
- package org.cove.ape
- {
- import flash.display.Sprite;
- import flash.utils.getQualifiedClassName;
-
- public class AbstractCollection
- {
-
-
- private var _sprite:Sprite;
-
- private var _isParented:Boolean;
-
- private var _particles:Array;
-
- private var _constraints:Array;
-
- public function AbstractCollection()
- {
- super();
- if(getQualifiedClassName(this) == "org.cove.ape::AbstractCollection")
- {
- throw new ArgumentError("AbstractCollection can\'t be instantiated directly");
- }
- _isParented = false;
- _particles = new Array();
- _constraints = new Array();
- }
-
- public function getAll() : Array
- {
- return particles.concat(constraints);
- }
-
- internal function checkCollisionsVsCollection(param1:AbstractCollection) : void
- {
- var _loc2_:int = 0;
- var _loc3_:int = 0;
- var _loc4_:int = 0;
- var _loc5_:AbstractParticle = null;
- var _loc6_:int = 0;
- var _loc7_:int = 0;
- var _loc8_:int = 0;
- var _loc9_:AbstractParticle = null;
- var _loc10_:SpringConstraint = null;
- var _loc11_:SpringConstraint = null;
- var _loc12_:int = 0;
- _loc2_ = int(_particles.length);
- _loc3_ = 0;
- while(_loc3_ < _loc2_)
- {
- if((_loc5_ = _particles[_loc3_]).collidable)
- {
- _loc6_ = int(param1.particles.length);
- _loc7_ = 0;
- while(_loc7_ < _loc6_)
- {
- if((_loc9_ = param1.particles[_loc7_]).collidable)
- {
- CollisionDetector.test(_loc5_,_loc9_);
- }
- _loc7_++;
- }
- _loc8_ = int(param1.constraints.length);
- _loc7_ = 0;
- while(_loc7_ < _loc8_)
- {
- if((_loc10_ = param1.constraints[_loc7_]).collidable && !_loc10_.isConnectedTo(_loc5_))
- {
- _loc10_.scp.updatePosition();
- CollisionDetector.test(_loc5_,_loc10_.scp);
- }
- _loc7_++;
- }
- }
- _loc3_++;
- }
- _loc4_ = int(_constraints.length);
- _loc3_ = 0;
- while(_loc3_ < _loc4_)
- {
- if((_loc11_ = _constraints[_loc3_]).collidable)
- {
- _loc6_ = int(param1.particles.length);
- _loc12_ = 0;
- while(_loc12_ < _loc6_)
- {
- if((_loc9_ = param1.particles[_loc12_]).collidable && !_loc11_.isConnectedTo(_loc9_))
- {
- _loc11_.scp.updatePosition();
- CollisionDetector.test(_loc9_,_loc11_.scp);
- }
- _loc12_++;
- }
- }
- _loc3_++;
- }
- }
-
- public function get sprite() : Sprite
- {
- if(_sprite != null)
- {
- return _sprite;
- }
- if(APEngine.container == null)
- {
- throw new Error("The container property of the APEngine class has not been set");
- }
- _sprite = new Sprite();
- APEngine.container.addChild(_sprite);
- return _sprite;
- }
-
- internal function checkInternalCollisions() : void
- {
- var _loc1_:int = 0;
- var _loc2_:int = 0;
- var _loc3_:AbstractParticle = null;
- var _loc4_:int = 0;
- var _loc5_:int = 0;
- var _loc6_:int = 0;
- var _loc7_:AbstractParticle = null;
- var _loc8_:SpringConstraint = null;
- _loc1_ = int(_particles.length);
- _loc2_ = 0;
- while(_loc2_ < _loc1_)
- {
- _loc3_ = _particles[_loc2_];
- if(_loc3_.collidable)
- {
- _loc4_ = _loc2_ + 1;
- while(_loc4_ < _loc1_)
- {
- if((_loc7_ = _particles[_loc4_]).collidable)
- {
- CollisionDetector.test(_loc3_,_loc7_);
- }
- _loc4_++;
- }
- _loc5_ = int(_constraints.length);
- _loc6_ = 0;
- while(_loc6_ < _loc5_)
- {
- if((_loc8_ = _constraints[_loc6_]).collidable && !_loc8_.isConnectedTo(_loc3_))
- {
- _loc8_.scp.updatePosition();
- CollisionDetector.test(_loc3_,_loc8_.scp);
- }
- _loc6_++;
- }
- }
- _loc2_++;
- }
- }
-
- public function addParticle(param1:AbstractParticle) : void
- {
- particles.push(param1);
- if(isParented)
- {
- param1.init();
- }
- }
-
- public function removeConstraint(param1:AbstractConstraint) : void
- {
- var _loc2_:int = 0;
- _loc2_ = constraints.indexOf(param1);
- if(_loc2_ == -1)
- {
- return;
- }
- constraints.splice(_loc2_,1);
- param1.cleanup();
- }
-
- internal function get isParented() : Boolean
- {
- return _isParented;
- }
-
- public function init() : void
- {
- var _loc1_:int = 0;
- _loc1_ = 0;
- while(_loc1_ < particles.length)
- {
- particles[_loc1_].init();
- _loc1_++;
- }
- _loc1_ = 0;
- while(_loc1_ < constraints.length)
- {
- constraints[_loc1_].init();
- _loc1_++;
- }
- }
-
- internal function satisfyConstraints() : void
- {
- var _loc1_:int = 0;
- var _loc2_:int = 0;
- var _loc3_:AbstractConstraint = null;
- _loc1_ = int(_constraints.length);
- _loc2_ = 0;
- while(_loc2_ < _loc1_)
- {
- _loc3_ = _constraints[_loc2_];
- _loc3_.resolve();
- _loc2_++;
- }
- }
-
- public function paint() : void
- {
- var _loc1_:AbstractParticle = null;
- var _loc2_:int = 0;
- var _loc3_:int = 0;
- var _loc4_:SpringConstraint = null;
- _loc2_ = int(_particles.length);
- _loc3_ = 0;
- while(_loc3_ < _loc2_)
- {
- _loc1_ = _particles[_loc3_];
- if(!_loc1_.fixed || _loc1_.alwaysRepaint)
- {
- _loc1_.paint();
- }
- _loc3_++;
- }
- _loc2_ = int(_constraints.length);
- _loc3_ = 0;
- while(_loc3_ < _loc2_)
- {
- if(!(_loc4_ = _constraints[_loc3_]).fixed || _loc4_.alwaysRepaint)
- {
- _loc4_.paint();
- }
- _loc3_++;
- }
- }
-
- public function addConstraint(param1:AbstractConstraint) : void
- {
- constraints.push(param1);
- if(isParented)
- {
- param1.init();
- }
- }
-
- internal function set isParented(param1:Boolean) : void
- {
- _isParented = param1;
- }
-
- public function removeParticle(param1:AbstractParticle) : void
- {
- var _loc2_:int = 0;
- _loc2_ = particles.indexOf(param1);
- if(_loc2_ == -1)
- {
- return;
- }
- particles.splice(_loc2_,1);
- param1.cleanup();
- }
-
- public function cleanup() : void
- {
- var _loc1_:int = 0;
- _loc1_ = 0;
- while(_loc1_ < particles.length)
- {
- particles[_loc1_].cleanup();
- _loc1_++;
- }
- _loc1_ = 0;
- while(_loc1_ < constraints.length)
- {
- constraints[_loc1_].cleanup();
- _loc1_++;
- }
- }
-
- public function get particles() : Array
- {
- return _particles;
- }
-
- internal function integrate(param1:Number) : void
- {
- var _loc2_:int = 0;
- var _loc3_:int = 0;
- var _loc4_:AbstractParticle = null;
- _loc2_ = int(_particles.length);
- _loc3_ = 0;
- while(_loc3_ < _loc2_)
- {
- (_loc4_ = _particles[_loc3_]).update(param1);
- _loc3_++;
- }
- }
-
- public function get constraints() : Array
- {
- return _constraints;
- }
- }
- }
-