hedgewars/uLandGraphics.pas
changeset 511 2b5b9e00419d
parent 505 fcba7d7aea0d
child 520 e83dfb7ffead
equal deleted inserted replaced
510:4e994e1b7abb 511:2b5b9e00419d
    28 
    28 
    29 procedure DrawExplosion(X, Y, Radius: LongInt);
    29 procedure DrawExplosion(X, Y, Radius: LongInt);
    30 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
    30 procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte);
    31 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
    31 procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt);
    32 procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword);
    32 procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword);
    33 procedure ChangeRoundInLand(X, Y, Radius: LongInt; Delta: LongInt);
    33 procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean);
    34 
    34 
    35 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): boolean;
    35 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): boolean;
    36 
    36 
    37 implementation
    37 implementation
    38 uses SDLh, uMisc, uLand;
    38 uses SDLh, uMisc, uLand;
    48    for i:= max(x - dy, 0) to min(x + dy, 2047) do Land[y + dx, i]:= Value;
    48    for i:= max(x - dy, 0) to min(x + dy, 2047) do Land[y + dx, i]:= Value;
    49 if ((y - dx) and $FFFFFC00) = 0 then
    49 if ((y - dx) and $FFFFFC00) = 0 then
    50    for i:= max(x - dy, 0) to min(x + dy, 2047) do Land[y - dx, i]:= Value;
    50    for i:= max(x - dy, 0) to min(x + dy, 2047) do Land[y - dx, i]:= Value;
    51 end;
    51 end;
    52 
    52 
    53 procedure ChangeCircleLines(x, y, dx, dy: LongInt; Delta: LongInt);
    53 procedure ChangeCircleLines(x, y, dx, dy: LongInt; doSet: boolean);
    54 var i: LongInt;
    54 var i: LongInt;
    55 begin
    55 begin
    56 if ((y + dy) and $FFFFFC00) = 0 then
    56 if not doSet then
    57    for i:= max(x - dx, 0) to min(x + dx, 2047) do inc(Land[y + dy, i], Delta);
    57    begin
    58 if ((y - dy) and $FFFFFC00) = 0 then
    58    if ((y + dy) and $FFFFFC00) = 0 then
    59    for i:= max(x - dx, 0) to min(x + dx, 2047) do inc(Land[y - dy, i], Delta);
    59       for i:= max(x - dx, 0) to min(x + dx, 2047) do
    60 if ((y + dx) and $FFFFFC00) = 0 then
    60           if (Land[y + dy, i] > 0) then dec(Land[y + dy, i]);
    61    for i:= max(x - dy, 0) to min(x + dy, 2047) do inc(Land[y + dx, i], Delta);
    61    if ((y - dy) and $FFFFFC00) = 0 then
    62 if ((y - dx) and $FFFFFC00) = 0 then
    62       for i:= max(x - dx, 0) to min(x + dx, 2047) do
    63    for i:= max(x - dy, 0) to min(x + dy, 2047) do inc(Land[y - dx, i], Delta);
    63           if (Land[y - dy, i] > 0) then dec(Land[y - dy, i]);
       
    64    if ((y + dx) and $FFFFFC00) = 0 then
       
    65       for i:= max(x - dy, 0) to min(x + dy, 2047) do
       
    66           if (Land[y + dx, i] > 0) then dec(Land[y + dx, i]);
       
    67    if ((y - dx) and $FFFFFC00) = 0 then
       
    68       for i:= max(x - dy, 0) to min(x + dy, 2047) do
       
    69           if (Land[y - dx, i] > 0) then dec(Land[y - dx, i]);
       
    70    end else
       
    71    begin
       
    72    if ((y + dy) and $FFFFFC00) = 0 then
       
    73       for i:= max(x - dx, 0) to min(x + dx, 2047) do inc(Land[y + dy, i]);
       
    74    if ((y - dy) and $FFFFFC00) = 0 then
       
    75       for i:= max(x - dx, 0) to min(x + dx, 2047) do inc(Land[y - dy, i]);
       
    76    if ((y + dx) and $FFFFFC00) = 0 then
       
    77       for i:= max(x - dy, 0) to min(x + dy, 2047) do inc(Land[y + dx, i]);
       
    78    if ((y - dx) and $FFFFFC00) = 0 then
       
    79       for i:= max(x - dy, 0) to min(x + dy, 2047) do inc(Land[y - dx, i]);
       
    80    end
    64 end;
    81 end;
    65 
    82 
    66 procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword);
    83 procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword);
    67 var dx, dy, d: LongInt;
    84 var dx, dy, d: LongInt;
    68 begin
    85 begin
    81      inc(dx)
    98      inc(dx)
    82      end;
    99      end;
    83   if (dx = dy) then FillCircleLines(x, y, dx, dy, Value);
   100   if (dx = dy) then FillCircleLines(x, y, dx, dy, Value);
    84 end;
   101 end;
    85 
   102 
    86 procedure ChangeRoundInLand(X, Y, Radius: LongInt; Delta: LongInt);
   103 procedure ChangeRoundInLand(X, Y, Radius: LongInt; doSet: boolean);
    87 var dx, dy, d: LongInt;
   104 var dx, dy, d: LongInt;
    88 begin
   105 begin
    89   dx:= 0;
   106   dx:= 0;
    90   dy:= Radius;
   107   dy:= Radius;
    91   d:= 3 - 2 * Radius;
   108   d:= 3 - 2 * Radius;
    92   while (dx < dy) do
   109   while (dx < dy) do
    93      begin
   110      begin
    94      ChangeCircleLines(x, y, dx, dy, Delta);
   111      ChangeCircleLines(x, y, dx, dy, doSet);
    95      if (d < 0)
   112      if (d < 0)
    96      then d:= d + 4 * dx + 6
   113      then d:= d + 4 * dx + 6
    97      else begin
   114      else begin
    98           d:= d + 4 * (dx - dy) + 10;
   115           d:= d + 4 * (dx - dy) + 10;
    99           dec(dy)
   116           dec(dy)
   100           end;
   117           end;
   101      inc(dx)
   118      inc(dx)
   102      end;
   119      end;
   103   if (dx = dy) then ChangeCircleLines(x, y, dx, dy, Delta);
   120   if (dx = dy) then ChangeCircleLines(x, y, dx, dy, doSet)
   104 end;
   121 end;
   105 
   122 
   106 procedure ClearLandPixel(y, x: LongInt);
   123 procedure ClearLandPixel(y, x: LongInt);
   107 var p: PByteArray;
   124 var p: PByteArray;
   108 begin
   125 begin
   275         X:= X + dX;
   292         X:= X + dX;
   276         Y:= Y + dY;
   293         Y:= Y + dY;
   277         tx:= hwRound(X);
   294         tx:= hwRound(X);
   278         ty:= hwRound(Y);
   295         ty:= hwRound(Y);
   279         if ((ty and $FFFFFC00) = 0) and ((tx and $FFFFF800) = 0) then
   296         if ((ty and $FFFFFC00) = 0) and ((tx and $FFFFF800) = 0) then
       
   297          if Land[ty, tx] = COLOR_LAND then
   280            begin
   298            begin
   281            Land[ty, tx]:= 0;
   299            Land[ty, tx]:= 0;
   282            ClearLandPixel(ty, tx);
   300            ClearLandPixel(ty, tx);
   283            end
   301            end
   284         end;
   302         end;