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

  1. class Pirrest.PhisicsEngine.Wheel extends MovieClip
  2. {
  3.    var _coord_space;
  4.    var wr;
  5.    var wp;
  6.    var rp;
  7.    var contactRadius;
  8.    var coeffSlip;
  9.    var closestPoint;
  10.    function Wheel()
  11.    {
  12.       super();
  13.    }
  14.    function init($coord_space, $mass)
  15.    {
  16.       if(Pirrest.Common.PiVal.isEmpty($coord_space))
  17.       {
  18.          this._coord_space = this._parent;
  19.       }
  20.       else
  21.       {
  22.          this._coord_space = $coord_space;
  23.       }
  24.       var _loc2_ = {x:this._x,y:this._y};
  25.       this._parent.localToGlobal(_loc2_);
  26.       $coord_space.globalToLocal(_loc2_);
  27.       this.wr = this._width / 2;
  28.       this.wp = new Pirrest.PhisicsEngine.Particle(_loc2_.x,_loc2_.y,$mass);
  29.       this.rp = new Pirrest.PhisicsEngine.RimParticle(this.wr,2);
  30.       this.contactRadius = this.wr;
  31.       this.coeffSlip = 0.1;
  32.       this.closestPoint = new Pirrest.PhisicsEngine.Vector(0,0);
  33.    }
  34.    function verlet($sysObj)
  35.    {
  36.       this.rp.verlet($sysObj);
  37.       this.wp.verlet($sysObj);
  38.    }
  39.    function checkCollision($surface, $sysObj)
  40.    {
  41.       $surface.resolveWheelCollision(this);
  42.    }
  43.    function paint()
  44.    {
  45.       var _loc7_ = this.wp.curr.x;
  46.       var _loc6_ = this.wp.curr.y;
  47.       var _loc4_ = this.rp.curr.x;
  48.       var _loc2_ = this.rp.curr.y;
  49.       this._x = _loc7_;
  50.       this._y = _loc6_;
  51.       var _loc3_ = 57.29578;
  52.       var _loc5_ = (- Math.atan2(_loc4_,_loc2_)) * _loc3_;
  53.       this._rotation = _loc5_;
  54.    }
  55.    function resolve($n)
  56.    {
  57.       var _loc3_ = - this.rp.curr.y;
  58.       var _loc2_ = this.rp.curr.x;
  59.       var _loc4_ = Math.sqrt(_loc3_ * _loc3_ + _loc2_ * _loc2_);
  60.       _loc3_ /= _loc4_;
  61.       _loc2_ /= _loc4_;
  62.       var _loc13_ = _loc3_ * this.rp.speed;
  63.       var _loc11_ = _loc2_ * this.rp.speed;
  64.       var _loc12_ = this.wp.curr.x - this.wp.prev.x;
  65.       var _loc10_ = this.wp.curr.y - this.wp.prev.y;
  66.       var _loc9_ = _loc12_ + _loc13_;
  67.       var _loc8_ = _loc10_ + _loc11_;
  68.       var _loc6_ = (- $n.y) * _loc9_ + $n.x * _loc8_;
  69.       this.rp.prev.x = this.rp.curr.x - _loc6_ * _loc3_;
  70.       this.rp.prev.y = this.rp.curr.y - _loc6_ * _loc2_;
  71.       var _loc7_ = 1 - this.coeffSlip;
  72.       this.wp.curr.x += _loc7_ * this.rp.speed * (- $n.y);
  73.       this.wp.curr.y += _loc7_ * this.rp.speed * $n.x;
  74.       this.rp.speed *= this.coeffSlip;
  75.    }
  76. }
  77.