home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Aventura / starisland.swf / scripts / __Packages / org / cove / flade / DynamicsEngine.as
Encoding:
Text File  |  2007-12-10  |  4.1 KB  |  179 lines

  1. class org.cove.flade.DynamicsEngine
  2. {
  3.    var primitives;
  4.    var surfaces;
  5.    var MoveSurfaces;
  6.    var constraints;
  7.    var gravity;
  8.    var coeffRest;
  9.    var coeffFric;
  10.    var coeffDamp;
  11.    var totalTime = 0;
  12.    function DynamicsEngine()
  13.    {
  14.       this.primitives = new Array();
  15.       this.surfaces = new Array();
  16.       this.MoveSurfaces = new Array();
  17.       this.constraints = new Array();
  18.       this.gravity = new org.cove.flade.util.Vector(0,1);
  19.       this.coeffRest = 1.5;
  20.       this.coeffFric = 0.01;
  21.       this.coeffDamp = 0.99;
  22.    }
  23.    function ClearSurfaces()
  24.    {
  25.       var _loc2_ = 0;
  26.       while(_loc2_ < this.surfaces.length)
  27.       {
  28.          this.surfaces[_loc2_].clear();
  29.          _loc2_ = _loc2_ + 1;
  30.       }
  31.       _loc2_ = 0;
  32.       while(_loc2_ < this.MoveSurfaces.length)
  33.       {
  34.          this.MoveSurfaces[_loc2_].clear();
  35.          _loc2_ = _loc2_ + 1;
  36.       }
  37.       this.surfaces = new Array();
  38.       this.MoveSurfaces = new Array();
  39.    }
  40.    function ClearAll()
  41.    {
  42.       this.surfaces = new Array();
  43.       this.MoveSurfaces = new Array();
  44.       this.constraints = new Array();
  45.    }
  46.    function addPrimitive(p)
  47.    {
  48.       this.primitives.push(p);
  49.    }
  50.    function addSurface(s)
  51.    {
  52.       this.surfaces.push(s);
  53.    }
  54.    function addMoveSurface(s)
  55.    {
  56.       this.MoveSurfaces.push(s);
  57.    }
  58.    function addConstraint(c)
  59.    {
  60.       this.constraints.push(c);
  61.    }
  62.    function paintSurfaces()
  63.    {
  64.       var _loc2_ = 0;
  65.       while(_loc2_ < this.surfaces.length)
  66.       {
  67.          this.surfaces[_loc2_].paint();
  68.          _loc2_ = _loc2_ + 1;
  69.       }
  70.    }
  71.    function paintMoveSurfaces()
  72.    {
  73.       var _loc2_ = 0;
  74.       while(_loc2_ < this.MoveSurfaces.length)
  75.       {
  76.          this.MoveSurfaces[_loc2_].paint();
  77.          _loc2_ = _loc2_ + 1;
  78.       }
  79.    }
  80.    function paintPrimitives()
  81.    {
  82.       var _loc2_ = 0;
  83.       while(_loc2_ < this.primitives.length)
  84.       {
  85.          this.primitives[_loc2_].paint();
  86.          _loc2_ = _loc2_ + 1;
  87.       }
  88.    }
  89.    function paintConstraints()
  90.    {
  91.       var _loc2_ = 0;
  92.       while(_loc2_ < this.constraints.length)
  93.       {
  94.          this.constraints[_loc2_].paint();
  95.          _loc2_ = _loc2_ + 1;
  96.       }
  97.    }
  98.    function timeStep()
  99.    {
  100.       this.verlet();
  101.       this.satisfyConstraints();
  102.       this.checkCollisions();
  103.    }
  104.    function setSurfaceBounce(kfr)
  105.    {
  106.       this.coeffRest = 1 + kfr;
  107.    }
  108.    function setSurfaceFriction(f)
  109.    {
  110.       this.coeffFric = f;
  111.    }
  112.    function setDamping(d)
  113.    {
  114.       this.coeffDamp = d;
  115.    }
  116.    function setGravity(gx, gy)
  117.    {
  118.       this.gravity.x = gx;
  119.       this.gravity.y = gy;
  120.    }
  121.    function verlet()
  122.    {
  123.       var _loc2_ = 0;
  124.       while(_loc2_ < this.primitives.length)
  125.       {
  126.          this.primitives[_loc2_].verlet(this);
  127.          _loc2_ = _loc2_ + 1;
  128.       }
  129.    }
  130.    function satisfyConstraints()
  131.    {
  132.       var _loc2_ = 0;
  133.       while(_loc2_ < this.constraints.length)
  134.       {
  135.          this.constraints[_loc2_].resolve();
  136.          _loc2_ = _loc2_ + 1;
  137.       }
  138.    }
  139.    function checkCollisions()
  140.    {
  141.       var _loc5_ = 0;
  142.       while(_loc5_ < this.primitives.length)
  143.       {
  144.          this.primitives[_loc5_].UpdateCount();
  145.          _loc5_ = _loc5_ + 1;
  146.       }
  147.       var _loc4_ = 0;
  148.       while(_loc4_ < this.surfaces.length)
  149.       {
  150.          var _loc3_ = this.surfaces[_loc4_];
  151.          if(_loc3_.getActiveState())
  152.          {
  153.             var _loc2_ = 0;
  154.             while(_loc2_ < this.primitives.length)
  155.             {
  156.                this.primitives[_loc2_].checkCollision(_loc3_,this);
  157.                _loc2_ = _loc2_ + 1;
  158.             }
  159.          }
  160.          _loc4_ = _loc4_ + 1;
  161.       }
  162.       _loc4_ = 0;
  163.       while(_loc4_ < this.MoveSurfaces.length)
  164.       {
  165.          _loc3_ = this.MoveSurfaces[_loc4_];
  166.          if(_loc3_.getActiveState())
  167.          {
  168.             _loc2_ = 0;
  169.             while(_loc2_ < this.primitives.length)
  170.             {
  171.                this.primitives[_loc2_].checkCollision(_loc3_,this);
  172.                _loc2_ = _loc2_ + 1;
  173.             }
  174.          }
  175.          _loc4_ = _loc4_ + 1;
  176.       }
  177.    }
  178. }
  179.