Advertisement
henke37

ds blend select

Apr 2nd, 2013
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. function drawPixel(x:uint,y:uint):uint {
  3.     //layers are assumed to already be sorted correctly based on priorities
  4.     const layers:Array=[OBJ_ALPHA,OBJ0,BG0,OBJ1,BG1,OBJ2,BG2,OBJ3,BG3];
  5.     var hasFirstColor:Boolean=false;
  6.    
  7.     var allowBlend:Boolean=false;
  8.     var isObjAlpha:Boolean=false;
  9.  
  10.     var outWindowEnabled:Boolean=window0.enabled || window1.enabled || oamWindow.enabled;
  11.    
  12.     if(window0.enabled && window0.pixelIn(x,y)) {
  13.         allowBlend=window0.blend;
  14.     } else if(window1.enabled && window1.pixelIn(x,y)) {
  15.         allowBlend=window1.blend;
  16.     } else if(oamWindow.enabled && oamWindow.pixelIn(x,y)) {
  17.         allowBlend=oamWindow.blend;
  18.     } else if(outWindowEnabled) {
  19.         allowBlend=outWindowBlend;
  20.     } else {
  21.         allowBlend=true;
  22.     }
  23.    
  24.     var firstColor:uint;
  25.     var secondColor:uint;
  26.    
  27.     for each(var layer:Layer in layers) {
  28.         if(!layer.enabled) continue;
  29.         var layerColor:uint=layer.sample(x,y);
  30.         if(isTransparent(layerColor)) continue;
  31.        
  32.         if(layer==OBJ_ALPHA) {
  33.             isObjAlpha=true;
  34.             allowBlend=true;
  35.         }
  36.        
  37.         if(allowBlend && !isObjAlpha) {
  38.             if(!hasFirstColor) {
  39.                 if(!layer.blendFromEnabled) continue;
  40.             } else {
  41.                 if(!layer.blendToEnabled) continue;
  42.             }
  43.         }
  44.        
  45.         if(!hasFirstColor) {
  46.             firstLayer=layerColor;
  47.             hasFirstColor=true;
  48.             if(!allowBlend) break;
  49.         } else {
  50.             secondColor=layerColor;
  51.             break;
  52.         }
  53.        
  54.     }
  55.    
  56.     if(!hasFirstColor) {
  57.         firstColor=BG0.basicPalette[0];
  58.     }
  59.    
  60.     var blendOpThisPixel:BlendOp=masterBlendOp;
  61.     if(!isTransparent(secondColor) && isObjAlpha) {
  62.         blendOpThisPixel=AlphaBlend;
  63.     }
  64.     return blendOpThisPixel(firstColor,secondColor);
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement