home *** CD-ROM | disk | FTP | other *** search
/ Mobiclic 161 / MOBICLIC161.ISO / pc / DATA / DSS161 / DSS161_00 / DSS161_00.swf / scripts / dss161 / engineaddons / gamesprotos / CollisionTest.as < prev    next >
Text File  |  2014-01-15  |  4KB  |  140 lines

  1. package dss161.engineaddons.gamesprotos
  2. {
  3.    import dss161.engineaddons.gamesprotos.actors.actorClip.ActorClip;
  4.    import flash.display.DisplayObject;
  5.    import flash.display.MovieClip;
  6.    import flash.geom.Point;
  7.    
  8.    public class CollisionTest
  9.    {
  10.        
  11.       
  12.       private var actor:ActorClip;
  13.       
  14.       private var _clip:MovieClip;
  15.       
  16.       protected var hitTestDistanceParams:Object;
  17.       
  18.       public function CollisionTest(param1:ActorClip)
  19.       {
  20.          this.hitTestDistanceParams = {"distanceMini":100000};
  21.          super();
  22.          this.actor = param1;
  23.          this._clip = param1.clip;
  24.       }
  25.       
  26.       public function withActor(param1:Actor) : Boolean
  27.       {
  28.          return this.hitTestObjects([param1]) != null;
  29.       }
  30.       
  31.       public function withDisplayObject(param1:DisplayObject) : void
  32.       {
  33.       }
  34.       
  35.       public function withCoord(param1:Number, param2:Number, param3:* = null) : void
  36.       {
  37.       }
  38.       
  39.       public function withPoint(param1:Point, param2:* = null) : void
  40.       {
  41.       }
  42.       
  43.       public function getNearestClip(param1:Array) : *
  44.       {
  45.          var _loc8_:Point = null;
  46.          var _loc2_:Number = -1;
  47.          var _loc3_:Number = 0;
  48.          var _loc4_:* = null;
  49.          var _loc5_:Point = this.actor.getLocPoint(this._clip);
  50.          var _loc6_:Point = new Point(0,0);
  51.          var _loc7_:int = 0;
  52.          while(_loc7_ < param1.length)
  53.          {
  54.             _loc8_ = new Point(param1[_loc7_].x,param1[_loc7_].y);
  55.             _loc5_ = this.actor.getPos();
  56.             _loc6_ = param1[_loc7_].parent.localToGlobal(_loc8_);
  57.             _loc3_ = Point.distance(_loc5_,_loc6_);
  58.             if(_loc3_ <= this.hitTestDistanceParams.distanceMini && (_loc2_ < 0 || _loc3_ < _loc2_))
  59.             {
  60.                _loc2_ = _loc3_;
  61.                _loc4_ = param1[_loc7_];
  62.             }
  63.             _loc7_++;
  64.          }
  65.          return _loc4_;
  66.       }
  67.       
  68.       protected function hitTestObjects(param1:Array) : *
  69.       {
  70.          var _loc2_:DisplayObject = null;
  71.          var _loc3_:DisplayObject = null;
  72.          var _loc4_:int = 0;
  73.          var _loc5_:int = 0;
  74.          var _loc6_:int = 0;
  75.          var _loc7_:Array = [];
  76.          if(this.actor.hitZones.length > 0)
  77.          {
  78.             _loc4_ = 0;
  79.             while(_loc4_ < this.actor.hitZones.length)
  80.             {
  81.                _loc2_ = this.actor.hitZones[_loc4_];
  82.                _loc5_ = 0;
  83.                while(_loc5_ < param1.length)
  84.                {
  85.                   if(param1[_loc5_].hitZones.length > 0)
  86.                   {
  87.                      _loc6_ = 0;
  88.                      while(_loc6_ < param1[_loc5_].hitZones.length)
  89.                      {
  90.                         _loc3_ = param1[_loc5_].hitZones[_loc6_];
  91.                         if(_loc2_.hitTestObject(_loc3_))
  92.                         {
  93.                            _loc7_.push(param1[_loc5_]);
  94.                         }
  95.                         _loc6_++;
  96.                      }
  97.                   }
  98.                   else if(_loc2_.hitTestObject(param1[_loc5_].clip))
  99.                   {
  100.                      _loc7_.push(param1[_loc5_]);
  101.                   }
  102.                   _loc5_++;
  103.                }
  104.                _loc4_++;
  105.             }
  106.             return this.getNearestClip(_loc7_);
  107.          }
  108.          _loc5_ = 0;
  109.          while(_loc5_ < param1.length)
  110.          {
  111.             if(param1[_loc5_].hitZones.length > 0)
  112.             {
  113.                _loc6_ = 0;
  114.                while(_loc6_ < param1[_loc5_].hitZones.length)
  115.                {
  116.                   _loc3_ = param1[_loc5_].hitZones[_loc6_];
  117.                   if(this._clip.hitTestObject(_loc3_))
  118.                   {
  119.                      _loc7_.push(param1[_loc5_]);
  120.                   }
  121.                   _loc6_++;
  122.                }
  123.             }
  124.             else if(this._clip.hitTestObject(param1[_loc5_].clip))
  125.             {
  126.                _loc7_.push(param1[_loc5_]);
  127.             }
  128.             _loc5_++;
  129.          }
  130.          return this.getNearestClip(_loc7_);
  131.       }
  132.       
  133.       public function destroy() : void
  134.       {
  135.          this.actor = null;
  136.          this._clip = null;
  137.       }
  138.    }
  139. }
  140.