matrefeytontias

[HaxePunk] Grid on Pixelmask/Imagemask collision checking

Sep 10th, 2016
546
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         _point.x = _parent.x + _x - _parent.originX;
  2.         _point.y = _parent.y + _y - _parent.originY;
  3.         if(Std.instance(other, Imagemask) != null) // 'other' inherits from Imagemask
  4.         {
  5.             _rect = cast(other, Imagemask).getBounds();
  6.             _rect.x += other._parent.x;
  7.             _rect.y += other._parent.y;
  8.         }
  9.         else
  10.         {
  11.             _rect.x = other._parent.x + other.x - other._parent.originX;
  12.             _rect.y = other._parent.y + other.y - other._parent.originY;
  13.             _rect.width = other.width;
  14.             _rect.height = other.height;
  15.         }
  16.        
  17.         var r1 = new Rectangle(_point.x, _point.y, _width, _height);
  18.        
  19.         var intersect = r1.intersection(_rect);
  20.        
  21.         trace(r1, _rect, intersect);
  22.        
  23.         if(intersect.isEmpty())
  24.             return false;
  25.        
  26.         for(dx in Math.floor(intersect.x - _rect.x) ...Math.floor(intersect.x - _rect.x + intersect.width))
  27.         {
  28.             for(dy in Math.floor(intersect.y - _rect.y) ...Math.floor(intersect.y - _rect.y + intersect.height))
  29.             {
  30.                 var tx = Std.int((dx + _rect.x) / _tile.width), ty = Std.int((dy + _rect.y) / _tile.height);
  31.                 if (data[ty][tx] && (other.data.getPixel32(dx, dy) >> 24) & 0xFF > 0)
  32.                 {
  33.                     return true;
  34.                 }
  35.             }
  36.         }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×