home *** CD-ROM | disk | FTP | other *** search
/ 600 Games / 600games.iso / Corrida / amazingrace.swf / scripts / __Packages / Pirrest / PhisicsEngine / Constraint.as < prev    next >
Encoding:
Text File  |  2006-06-13  |  1.1 KB  |  39 lines

  1. class Pirrest.PhisicsEngine.Constraint
  2. {
  3.    var p1;
  4.    var p2;
  5.    var restLength;
  6.    var dmc;
  7.    function Constraint($p1, $p2)
  8.    {
  9.       this.init($p1,$p2);
  10.    }
  11.    function init($p1, $p2)
  12.    {
  13.       this.p1 = $p1;
  14.       this.p2 = $p2;
  15.       this.restLength = $p1.curr.distance($p2.curr);
  16.       var _loc3_ = _root.main_mc.main_cont_mc.level_mc.over_mc.getNextHighestDepth();
  17.       this.dmc = _root.main_mc.main_cont_mc.level_mc.over_mc.createEmptyMovieClip("p_" + _loc3_,_loc3_);
  18.    }
  19.    function resolve()
  20.    {
  21.       var _loc5_ = this.p1.curr.minusNew(this.p2.curr);
  22.       var _loc3_ = this.p1.curr.distance(this.p2.curr);
  23.       var _loc4_ = (_loc3_ - this.restLength) / _loc3_;
  24.       var _loc2_ = _loc5_.mult(_loc4_ * 0.5);
  25.       this.p1.curr.minus(_loc2_);
  26.       this.p2.curr.plus(_loc2_);
  27.    }
  28.    function setRestLength($r)
  29.    {
  30.       this.restLength = $r;
  31.    }
  32.    function paint()
  33.    {
  34.       this.dmc.clear();
  35.       this.dmc.lineStyle(0,16711680,100);
  36.       Pirrest.PhisicsEngine.Graphics.prototype.paintLine(this.dmc,this.p1.curr.x,this.p1.curr.y,this.p2.curr.x,this.p2.curr.y);
  37.    }
  38. }
  39.