hedgewars/uLandGraphics.pas
branchicegun
changeset 8584 ea20d9cc8515
parent 8583 f2edd6d5f958
child 8588 47084c6fcb4e
equal deleted inserted replaced
8583:f2edd6d5f958 8584:ea20d9cc8515
   263 end;
   263 end;
   264 
   264 
   265 function getPixelWeight(x, y:Longint): Longint;
   265 function getPixelWeight(x, y:Longint): Longint;
   266 var
   266 var
   267     i, j:Longint;
   267     i, j:Longint;
   268 begin    
   268 begin
   269     result := 0;
   269     result := 0;
   270     for i := x - 1 to x + 1 do
   270     for i := x - 1 to x + 1 do
   271         for j := y - 1 to y + 1 do 
   271         for j := y - 1 to y + 1 do
   272         begin
   272         begin
   273         if (i < 0) or 
   273         if (i < 0) or
   274            (i > LAND_WIDTH - 1) or 
   274            (i > LAND_WIDTH - 1) or
   275            (j < 0) or 
   275            (j < 0) or
   276            (j > LAND_HEIGHT -1) or 
   276            (j > LAND_HEIGHT -1) or
   277            ((Land[j, i] and $FF00) = 0) then
   277            ((Land[j, i] and $FF00) = 0) then
   278            begin
   278            begin
   279            result := result + 1;
   279            result := result + 1;
   280            end;
   280            end;
   281         end;
   281         end;
   282 end;
   282 end;
   283 
   283 
   284 procedure drawIcePixel(y, x:Longint);
   284 procedure drawIcePixel(y, x:Longint);
   285 var 
   285 var
   286     iceSurface: PSDL_Surface;
   286     iceSurface: PSDL_Surface;
   287     icePixels: PLongwordArray;
   287     icePixels: PLongwordArray;
   288     pictureX, pictureY: LongInt;
   288     pictureX, pictureY: LongInt;
   289     w, c: LongWord;
   289     w, c: LongWord;
   290     weight: Longint;
   290     weight: Longint;
   291 begin
   291 begin
   292     weight := getPixelWeight(x, y);
   292     weight := getPixelWeight(x, y);
   293     if isLandscape(weight) then
   293     if isLandscape(weight) then
   294         begin
   294         begin
   295         // So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
   295         // So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
   296         c:= $7dc1ccff;
       
   297         // FIXME should be a global value, not set every single pixel.  Just for test purposes
       
   298         c:= ($44 shl RShift) or ($97 shl GShift) or ($A9 shl BShift) or ($A0 shl AShift);
       
   299         iceSurface:= SpritesData[sprIceTexture].Surface;
   296         iceSurface:= SpritesData[sprIceTexture].Surface;
   300         pictureX := x mod iceSurface^.w;
   297         pictureX := x mod iceSurface^.w;
   301         pictureY := y mod iceSurface^.h;
   298         pictureY := y mod iceSurface^.h;
   302         icePixels := iceSurface^.pixels;
   299         icePixels := iceSurface^.pixels;
   303         w:= LandPixels[y, x];
   300         w:= LandPixels[y, x];
   306               (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
   303               (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
   307         if w < 128 then w:= w+128;
   304         if w < 128 then w:= w+128;
   308         if w > 255 then w:= 255;
   305         if w > 255 then w:= 255;
   309         w:= (w shl RShift) or (w shl BShift) or (w shl GShift) or (LandPixels[y,x] and AMask);
   306         w:= (w shl RShift) or (w shl BShift) or (w shl GShift) or (LandPixels[y,x] and AMask);
   310         //LandPixels[y, x]:= w;
   307         //LandPixels[y, x]:= w;
   311         LandPixels[y, x]:= addBgColor(w, c);
   308         LandPixels[y, x]:= addBgColor(w, IceColor);
   312         LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)]);
   309         LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)]);
   313         Land[y, x] := land[y, x] or lfIce;            
   310         Land[y, x] := land[y, x] or lfIce;
   314         end
   311         end
   315     else if (isLandscapeEdge(weight)) then
   312     else if (isLandscapeEdge(weight)) then
   316         begin
   313         begin
   317             LandPixels[y, x] := $FFB2AF8A;                    
   314         LandPixels[y, x] := $FFB2AF8A;
   318             if Land[y, x] > 255 then Land[y, x] := Land[y, x] or lfIce;
   315         if Land[y, x] > 255 then Land[y, x] := Land[y, x] or lfIce;
   319         end;
   316         end;
   320 
   317 
   321 end;
   318 end;
   322 
   319 
   323 function getIncrementInquarter(dx, dy, quarter: Longint): Longint;
   320 function getIncrementInquarter(dx, dy, quarter: Longint): Longint;
   324 const directionX : array [0..3] of Longint = (0, 0, 1, -1);
   321 const directionX : array [0..3] of Longint = (0, 0, 1, -1);
   325 const directionY : array [0..3] of Longint = (1, -1, 0, 0);
   322 const directionY : array [0..3] of Longint = (1, -1, 0, 0);
   326 begin    
   323 begin
   327     getIncrementInquarter := directionX[quarter] * dx + directionY[quarter] * dy;
   324     getIncrementInquarter := directionX[quarter] * dx + directionY[quarter] * dy;
   328 end;
   325 end;
   329 
   326 
   330 function getIncrementInquarter2(dx, dy, quarter: Longint): Longint;
   327 function getIncrementInquarter2(dx, dy, quarter: Longint): Longint;
   331 const directionY : array [0..3] of Longint = (0, 0, 1, 1);
   328 const directionY : array [0..3] of Longint = (0, 0, 1, 1);
   332 const directionX : array [0..3] of Longint = (1, 1, 0, 0);
   329 const directionX : array [0..3] of Longint = (1, 1, 0, 0);
   333 begin    
   330 begin
   334     getIncrementInquarter2 := directionX[quarter] * dx + directionY[quarter] * dy;
   331     getIncrementInquarter2 := directionX[quarter] * dx + directionY[quarter] * dy;
   335 end;
   332 end;
   336 
   333 
   337 procedure FillLandCircleLinesIce(x, y, dx, dy: LongInt);
   334 procedure FillLandCircleLinesIce(x, y, dx, dy: LongInt);
   338 var q, i, t: LongInt;
   335 var q, i, t: LongInt;
   340 for q := 0 to 3 do
   337 for q := 0 to 3 do
   341     begin
   338     begin
   342         t:= y + getIncrementInquarter(dx, dy, q);
   339         t:= y + getIncrementInquarter(dx, dy, q);
   343         if (t and LAND_HEIGHT_MASK) = 0 then
   340         if (t and LAND_HEIGHT_MASK) = 0 then
   344             for i:= Max(x - getIncrementInquarter2(dx, dy, q), 0) to Min(x + getIncrementInquarter2(dx, dy, q), LAND_WIDTH - 1) do
   341             for i:= Max(x - getIncrementInquarter2(dx, dy, q), 0) to Min(x + getIncrementInquarter2(dx, dy, q), LAND_WIDTH - 1) do
   345                 if ((Land[t, i] and lfIndestructible) = 0) and (not disableLandBack or (Land[t, i] > 255))  then
   342                 if (Land[t, i] and (lfIndestructible or lfIce) = 0) and (not disableLandBack or (Land[t, i] > 255))  then
   346                     if (cReducedQuality and rqBlurryLand) = 0 then
   343                     if (cReducedQuality and rqBlurryLand) = 0 then
   347                        drawIcePixel(t, i)
   344                        drawIcePixel(t, i)
   348                     else
   345                     else
   349                        drawIcePixel(t div 2, i div 2) ;        
   346                        drawIcePixel(t div 2, i div 2) ;
   350     end;
   347     end;
   351 end;
   348 end;
   352 
   349 
   353 procedure FillRoundInLandWithIce(X, Y, Radius: LongInt);
   350 procedure FillRoundInLandWithIce(X, Y, Radius: LongInt);
   354 var dx, dy, d: LongInt;
   351 var dx, dy, d: LongInt;