home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / carreras.swf / scripts / __Packages / CollisionDetection.as
Encoding:
Text File  |  2008-09-26  |  1.6 KB  |  43 lines

  1. class CollisionDetection
  2. {
  3.    function CollisionDetection()
  4.    {
  5.    }
  6.    static function checkForCollision(p_clip1, p_clip2, p_alphaTolerance)
  7.    {
  8.       if(p_alphaTolerance == undefined)
  9.       {
  10.          p_alphaTolerance = 255;
  11.       }
  12.       _root.localToGlobal();
  13.       var _loc4_ = p_clip1.getBounds(_root);
  14.       var _loc3_ = p_clip2.getBounds(_root);
  15.       if(_loc4_.xMax < _loc3_.xMin || _loc3_.xMax < _loc4_.xMin || (_loc4_.yMax < _loc3_.yMin || _loc3_.yMax < _loc4_.yMin))
  16.       {
  17.          return null;
  18.       }
  19.       var _loc2_ = {};
  20.       _loc2_.xMin = Math.max(_loc4_.xMin,_loc3_.xMin);
  21.       _loc2_.xMax = Math.min(_loc4_.xMax,_loc3_.xMax);
  22.       _loc2_.yMin = Math.max(_loc4_.yMin,_loc3_.yMin);
  23.       _loc2_.yMax = Math.min(_loc4_.yMax,_loc3_.yMax);
  24.       var _loc7_ = new flash.display.BitmapData(_loc2_.xMax - _loc2_.xMin,_loc2_.yMax - _loc2_.yMin,false);
  25.       var _loc5_ = p_clip1.transform.concatenatedMatrix;
  26.       _loc5_.tx -= _loc2_.xMin;
  27.       _loc5_.ty -= _loc2_.yMin;
  28.       _loc7_.draw(p_clip1,_loc5_,new flash.geom.ColorTransform(1,1,1,1,255,-255,-255,p_alphaTolerance));
  29.       _loc5_ = p_clip2.transform.concatenatedMatrix;
  30.       _loc5_.tx -= _loc2_.xMin;
  31.       _loc5_.ty -= _loc2_.yMin;
  32.       _loc7_.draw(p_clip2,_loc5_,new flash.geom.ColorTransform(1,1,1,1,255,255,255,p_alphaTolerance),"difference");
  33.       var _loc6_ = _loc7_.getColorBoundsRect(4294967295,4278255615);
  34.       if(_loc6_.width == 0)
  35.       {
  36.          return null;
  37.       }
  38.       _loc6_.x += _loc2_.xMin;
  39.       _loc6_.y += _loc2_.yMin;
  40.       return _loc6_;
  41.    }
  42. }
  43.