hedgewars/uLandGraphics.pas
branchicegun
changeset 8586 191bd86ba000
parent 8585 da608f69d853
child 8587 6319accfa04a
equal deleted inserted replaced
8585:da608f69d853 8586:191bd86ba000
   245                 LandPixels[t div 2, i div 2]:= 0;
   245                 LandPixels[t div 2, i div 2]:= 0;
   246 
   246 
   247 end;
   247 end;
   248 
   248 
   249 
   249 
   250 function isLandscapeEdge(weight:Longint):boolean;
   250 
   251 begin
   251 
   252     result := (weight < 8) and (weight >= 2);
       
   253 end;
       
   254 
       
   255 function isLandscape(weight:Longint):boolean;
       
   256 begin
       
   257     result := weight < 2;
       
   258 end;
       
   259 
       
   260 function isEmptySpace(weight:Longint):boolean;
       
   261 begin
       
   262     result := not isLandscape(weight) and not isLandscapeEdge(weight);
       
   263 end;
       
   264 
   252 
   265 function getPixelWeight(x, y:Longint): Longint;
   253 function getPixelWeight(x, y:Longint): Longint;
   266 var
   254 var
   267     i, j:Longint;
   255     i, j:Longint;
   268 begin    
   256 begin    
   287     icePixels: PLongwordArray;
   275     icePixels: PLongwordArray;
   288     pictureX, pictureY: LongInt;
   276     pictureX, pictureY: LongInt;
   289     w, c: LongWord;
   277     w, c: LongWord;
   290     weight: Longint;
   278     weight: Longint;
   291 begin
   279 begin
   292     weight := getPixelWeight(x, y);
   280 weight := getPixelWeight(x, y);
   293     if (land[y, x] and lfIce) <> 0 then
   281 if (land[y, x] and lfIce) <> 0 then
   294         exit;
   282     exit;
   295     if isLandscape(weight) then
   283 //pixel in landscape
   296         begin
   284 if weight < 2 then
   297         // So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
   285     begin
   298         c:= $7dc1ccff;
   286     // So. 3 parameters here. Ice colour, Ice opacity, and a bias on the greyscaled pixel towards lightness
   299         // FIXME should be a global value, not set every single pixel.  Just for test purposes
   287     c:= $7dc1ccff;
   300         c:= ($44 shl RShift) or ($97 shl GShift) or ($A9 shl BShift) or ($A0 shl AShift);
   288     // FIXME should be a global value, not set every single pixel.  Just for test purposes
   301         iceSurface:= SpritesData[sprIceTexture].Surface;
   289     c:= ($44 shl RShift) or ($97 shl GShift) or ($A9 shl BShift) or ($A0 shl AShift);
   302         pictureX := x mod iceSurface^.w;
   290     iceSurface:= SpritesData[sprIceTexture].Surface;
   303         pictureY := y mod iceSurface^.h;
   291     pictureX := x mod iceSurface^.w;
   304         icePixels := iceSurface^.pixels;
   292     pictureY := y mod iceSurface^.h;
   305         w:= LandPixels[y, x];
   293     icePixels := iceSurface^.pixels;
   306         w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
   294     w:= LandPixels[y, x];
   307               (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
   295     w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
   308               (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
   296           (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
   309         if w < 128 then w:= w+128;
   297           (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
   310         if w > 255 then w:= 255;
   298     if w < 128 then w:= w+128;
   311         w:= (w shl RShift) or (w shl BShift) or (w shl GShift) or (LandPixels[y,x] and AMask);
   299     if w > 255 then w:= 255;
   312         //LandPixels[y, x]:= w;
   300     w:= (w shl RShift) or (w shl BShift) or (w shl GShift) or (LandPixels[y,x] and AMask);
   313         LandPixels[y, x]:= addBgColor(w, c);
   301     //LandPixels[y, x]:= w;
   314         LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)]);
   302     LandPixels[y, x]:= addBgColor(w, c);
   315         Land[y, x] := land[y, x] or lfIce;            
   303     LandPixels[y, x]:= addBgColor(LandPixels[y, x], icePixels^[iceSurface^.w * (y mod iceSurface^.h) + (x mod iceSurface^.w)]);
   316         end
   304     Land[y, x] := land[y, x] or lfIce;            
   317     else if (isLandscapeEdge(weight)) then
   305     end
   318         begin
   306 //pixel is on edge of lanscape
   319             LandPixels[y, x] := $FFB2AF8A;                    
   307 else if (weight < 8) then
   320             if Land[y, x] > 255 then Land[y, x] := Land[y, x] or lfIce;
   308     begin
   321         end;
   309         LandPixels[y, x] := $FFB2AF8A;                    
   322 
   310         if Land[y, x] > 255 then Land[y, x] := Land[y, x] or lfIce;
       
   311     end;
   323 end;
   312 end;
   324 
   313 
   325 function getIncrementInquarter(dx, dy, quarter: Longint): Longint;
   314 function getIncrementInquarter(dx, dy, quarter: Longint): Longint;
   326 const directionX : array [0..3] of Longint = (0, 0, 1, -1);
   315 const directionX : array [0..3] of Longint = (0, 0, 1, -1);
   327 const directionY : array [0..3] of Longint = (1, -1, 0, 0);
   316 const directionY : array [0..3] of Longint = (1, -1, 0, 0);
   352     end;
   341     end;
   353 end;
   342 end;
   354 
   343 
   355 procedure FillRoundInLandWithIce(X, Y, Radius: LongInt);
   344 procedure FillRoundInLandWithIce(X, Y, Radius: LongInt);
   356 var dx, dy, d: LongInt;
   345 var dx, dy, d: LongInt;
       
   346     landRect : TSDL_RECT;
   357 begin
   347 begin
   358 dx:= 0;
   348 dx:= 0;
   359 dy:= Radius;
   349 dy:= Radius;
   360 d:= 3 - 2 * Radius;
   350 d:= 3 - 2 * Radius;
   361     while (dx < dy) do
   351 while (dx < dy) do
   362         begin
   352     begin
   363         FillLandCircleLinesIce(x, y, dx, dy);
   353     FillLandCircleLinesIce(x, y, dx, dy);
   364         if (d < 0) then
   354     if (d < 0) then
   365             d:= d + 4 * dx + 6
   355         d:= d + 4 * dx + 6
   366         else
   356     else
   367             begin
   357         begin
   368             d:= d + 4 * (dx - dy) + 10;
   358         d:= d + 4 * (dx - dy) + 10;
   369             dec(dy)
   359         dec(dy)
   370             end;
   360         end;
   371         inc(dx)
   361     inc(dx)
   372         end;
   362     end;
   373     if (dx = dy) then
   363 if (dx = dy) then
   374         FillLandCircleLinesIce(x, y, dx, dy);
   364     FillLandCircleLinesIce(x, y, dx, dy);
       
   365 
       
   366 landRect.x := min(max(x - Radius, 0), LAND_WIDTH - 1);
       
   367 landRect.y := min(max(y - Radius, 0), LAND_HEIGHT - 1);
       
   368 landRect.w := min(2*Radius, LAND_WIDTH - landRect.x - 1);
       
   369 landRect.h := min(2*Radius, LAND_HEIGHT - landRect.y - 1);
       
   370 UpdateLandTexture(landRect.x, landRect.w, landRect.y, landRect.h, true);
   375 end;
   371 end;
   376 
   372 
   377 
   373 
   378 function FillLandCircleLinesBG(x, y, dx, dy: LongInt): Longword;
   374 function FillLandCircleLinesBG(x, y, dx, dy: LongInt): Longword;
   379 var i, t, by, bx: LongInt;
   375 var i, t, by, bx: LongInt;