184
|
1 |
unit uLandGraphics;
|
|
2 |
interface
|
351
|
3 |
uses uFloat;
|
345
|
4 |
{$INCLUDE options.inc}
|
184
|
5 |
|
|
6 |
type PRangeArray = ^TRangeArray;
|
|
7 |
TRangeArray = array[0..31] of record
|
|
8 |
Left, Right: integer;
|
|
9 |
end;
|
|
10 |
|
|
11 |
procedure DrawExplosion(X, Y, Radius: integer);
|
|
12 |
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: integer; y, dY: integer; Count: Byte);
|
351
|
13 |
procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: integer);
|
184
|
14 |
procedure FillRoundInLand(X, Y, Radius: integer; Value: Longword);
|
|
15 |
|
|
16 |
implementation
|
196
|
17 |
uses SDLh, uMisc, uLand, uConsts;
|
184
|
18 |
|
|
19 |
procedure FillCircleLines(x, y, dx, dy: integer; Value: Longword);
|
|
20 |
var i: integer;
|
|
21 |
begin
|
|
22 |
if ((y + dy) and $FFFFFC00) = 0 then
|
|
23 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do Land[y + dy, i]:= Value;
|
|
24 |
if ((y - dy) and $FFFFFC00) = 0 then
|
|
25 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do Land[y - dy, i]:= Value;
|
|
26 |
if ((y + dx) and $FFFFFC00) = 0 then
|
|
27 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do Land[y + dx, i]:= Value;
|
|
28 |
if ((y - dx) and $FFFFFC00) = 0 then
|
|
29 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do Land[y - dx, i]:= Value;
|
|
30 |
end;
|
|
31 |
|
|
32 |
procedure FillRoundInLand(X, Y, Radius: integer; Value: Longword);
|
|
33 |
var dx, dy, d: integer;
|
|
34 |
begin
|
|
35 |
dx:= 0;
|
|
36 |
dy:= Radius;
|
|
37 |
d:= 3 - 2 * Radius;
|
|
38 |
while (dx < dy) do
|
|
39 |
begin
|
|
40 |
FillCircleLines(x, y, dx, dy, Value);
|
|
41 |
if (d < 0)
|
|
42 |
then d:= d + 4 * dx + 6
|
|
43 |
else begin
|
|
44 |
d:= d + 4 * (dx - dy) + 10;
|
|
45 |
dec(dy)
|
|
46 |
end;
|
|
47 |
inc(dx)
|
|
48 |
end;
|
|
49 |
if (dx = dy) then FillCircleLines(x, y, dx, dy, Value);
|
|
50 |
end;
|
|
51 |
|
|
52 |
procedure ClearLandPixel(y, x: integer);
|
|
53 |
var p: PByteArray;
|
|
54 |
begin
|
351
|
55 |
p:= @PByteArray(LandSurface^.pixels)^[LandSurface^.pitch * y];
|
|
56 |
case LandSurface^.format^.BytesPerPixel of
|
184
|
57 |
1: ;// not supported
|
351
|
58 |
2: PWord(@(p^[x * 2]))^:= 0;
|
184
|
59 |
3: begin
|
351
|
60 |
p^[x * 3 + 0]:= 0;
|
|
61 |
p^[x * 3 + 1]:= 0;
|
|
62 |
p^[x * 3 + 2]:= 0;
|
184
|
63 |
end;
|
351
|
64 |
4: PLongword(@(p^[x * 4]))^:= 0;
|
184
|
65 |
end
|
|
66 |
end;
|
|
67 |
|
|
68 |
procedure SetLandPixel(y, x: integer);
|
|
69 |
var p: PByteArray;
|
|
70 |
begin
|
351
|
71 |
p:= @PByteArray(LandSurface^.pixels)^[LandSurface^.pitch * y];
|
|
72 |
case LandSurface^.format^.BytesPerPixel of
|
184
|
73 |
1: ;// not supported
|
351
|
74 |
2: PWord(@(p^[x * 2]))^:= cExplosionBorderColor;
|
184
|
75 |
3: begin
|
351
|
76 |
p^[x * 3 + 0]:= cExplosionBorderColor and $FF;
|
|
77 |
p^[x * 3 + 1]:= (cExplosionBorderColor shr 8) and $FF;
|
|
78 |
p^[x * 3 + 2]:= cExplosionBorderColor shr 16;
|
184
|
79 |
end;
|
351
|
80 |
4: PLongword(@(p^[x * 4]))^:= cExplosionBorderColor;
|
184
|
81 |
end
|
|
82 |
end;
|
|
83 |
|
|
84 |
procedure FillLandCircleLines0(x, y, dx, dy: integer);
|
|
85 |
var i: integer;
|
|
86 |
begin
|
|
87 |
if ((y + dy) and $FFFFFC00) = 0 then
|
|
88 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do ClearLandPixel(y + dy, i);
|
|
89 |
if ((y - dy) and $FFFFFC00) = 0 then
|
|
90 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do ClearLandPixel(y - dy, i);
|
|
91 |
if ((y + dx) and $FFFFFC00) = 0 then
|
|
92 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do ClearLandPixel(y + dx, i);
|
|
93 |
if ((y - dx) and $FFFFFC00) = 0 then
|
|
94 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do ClearLandPixel(y - dx, i);
|
|
95 |
end;
|
|
96 |
|
|
97 |
procedure FillLandCircleLinesEBC(x, y, dx, dy: integer);
|
|
98 |
var i: integer;
|
|
99 |
begin
|
|
100 |
if ((y + dy) and $FFFFFC00) = 0 then
|
|
101 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do
|
|
102 |
if Land[y + dy, i] = COLOR_LAND then SetLandPixel(y + dy, i);
|
|
103 |
if ((y - dy) and $FFFFFC00) = 0 then
|
|
104 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do
|
|
105 |
if Land[y - dy, i] = COLOR_LAND then SetLandPixel(y - dy, i);
|
|
106 |
if ((y + dx) and $FFFFFC00) = 0 then
|
|
107 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do
|
|
108 |
if Land[y + dx, i] = COLOR_LAND then SetLandPixel(y + dx, i);
|
|
109 |
if ((y - dx) and $FFFFFC00) = 0 then
|
|
110 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do
|
|
111 |
if Land[y - dx, i] = COLOR_LAND then SetLandPixel(y - dx, i);
|
|
112 |
end;
|
|
113 |
|
|
114 |
procedure DrawExplosion(X, Y, Radius: integer);
|
|
115 |
var dx, dy, d: integer;
|
|
116 |
begin
|
|
117 |
FillRoundInLand(X, Y, Radius, 0);
|
|
118 |
|
|
119 |
if SDL_MustLock(LandSurface) then
|
|
120 |
SDLTry(SDL_LockSurface(LandSurface) >= 0, true);
|
|
121 |
|
|
122 |
dx:= 0;
|
|
123 |
dy:= Radius;
|
|
124 |
d:= 3 - 2 * Radius;
|
|
125 |
while (dx < dy) do
|
|
126 |
begin
|
|
127 |
FillLandCircleLines0(x, y, dx, dy);
|
|
128 |
if (d < 0)
|
|
129 |
then d:= d + 4 * dx + 6
|
|
130 |
else begin
|
|
131 |
d:= d + 4 * (dx - dy) + 10;
|
|
132 |
dec(dy)
|
|
133 |
end;
|
|
134 |
inc(dx)
|
|
135 |
end;
|
|
136 |
if (dx = dy) then FillLandCircleLines0(x, y, dx, dy);
|
|
137 |
inc(Radius, 4);
|
|
138 |
dx:= 0;
|
|
139 |
dy:= Radius;
|
|
140 |
d:= 3 - 2 * Radius;
|
|
141 |
while (dx < dy) do
|
|
142 |
begin
|
|
143 |
FillLandCircleLinesEBC(x, y, dx, dy);
|
|
144 |
if (d < 0)
|
|
145 |
then d:= d + 4 * dx + 6
|
|
146 |
else begin
|
|
147 |
d:= d + 4 * (dx - dy) + 10;
|
|
148 |
dec(dy)
|
|
149 |
end;
|
|
150 |
inc(dx)
|
|
151 |
end;
|
351
|
152 |
if (dx = dy) then FillLandCircleLinesEBC(x, y, dx, dy);
|
|
153 |
|
184
|
154 |
if SDL_MustLock(LandSurface) then
|
|
155 |
SDL_UnlockSurface(LandSurface);
|
|
156 |
end;
|
|
157 |
|
|
158 |
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: integer; y, dY: integer; Count: Byte);
|
|
159 |
var tx, ty, i: LongInt;
|
|
160 |
begin
|
|
161 |
if SDL_MustLock(LandSurface) then
|
|
162 |
SDL_LockSurface(LandSurface);
|
|
163 |
|
|
164 |
for i:= 0 to Pred(Count) do
|
|
165 |
begin
|
188
|
166 |
for ty:= max(y - Radius, 0) to min(y + Radius, 1023) do
|
351
|
167 |
for tx:= max(0, ar^[i].Left - Radius) to min(2047, ar^[i].Right + Radius) do
|
188
|
168 |
ClearLandPixel(ty, tx);
|
184
|
169 |
inc(y, dY)
|
|
170 |
end;
|
|
171 |
|
|
172 |
inc(Radius, 4);
|
351
|
173 |
dec(y, Count * dY);
|
184
|
174 |
|
|
175 |
for i:= 0 to Pred(Count) do
|
|
176 |
begin
|
188
|
177 |
for ty:= max(y - Radius, 0) to min(y + Radius, 1023) do
|
351
|
178 |
for tx:= max(0, ar^[i].Left - Radius) to min(2047, ar^[i].Right + Radius) do
|
188
|
179 |
if Land[ty, tx] = $FFFFFF then
|
|
180 |
SetLandPixel(ty, tx);
|
184
|
181 |
inc(y, dY)
|
|
182 |
end;
|
|
183 |
|
|
184 |
if SDL_MustLock(LandSurface) then
|
|
185 |
SDL_UnlockSurface(LandSurface);
|
|
186 |
end;
|
|
187 |
|
|
188 |
//
|
|
189 |
// - (dX, dY) - direction, vector of length = 0.5
|
|
190 |
//
|
351
|
191 |
procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: integer);
|
358
|
192 |
var nx, ny, dX8, dY8: hwFloat;
|
184
|
193 |
i, t, tx, ty: Longint;
|
|
194 |
begin // (-dY, dX) is (dX, dY) rotated by PI/2
|
|
195 |
if SDL_MustLock(LandSurface) then
|
|
196 |
SDL_LockSurface(LandSurface);
|
|
197 |
|
|
198 |
nx:= X + dY * (HalfWidth + 8);
|
|
199 |
ny:= Y - dX * (HalfWidth + 8);
|
|
200 |
|
358
|
201 |
dX8:= dX * 8;
|
|
202 |
dY8:= dY * 8;
|
184
|
203 |
for i:= 0 to 7 do
|
|
204 |
begin
|
358
|
205 |
X:= nx - dX8;
|
|
206 |
Y:= ny - dY8;
|
184
|
207 |
for t:= -8 to ticks + 8 do
|
|
208 |
{$include tunsetborder.inc}
|
|
209 |
nx:= nx - dY;
|
|
210 |
ny:= ny + dX;
|
|
211 |
end;
|
|
212 |
|
|
213 |
for i:= -HalfWidth to HalfWidth do
|
|
214 |
begin
|
358
|
215 |
X:= nx - dX8;
|
|
216 |
Y:= ny - dY8;
|
184
|
217 |
for t:= 0 to 7 do
|
|
218 |
{$include tunsetborder.inc}
|
|
219 |
X:= nx;
|
|
220 |
Y:= ny;
|
|
221 |
for t:= 0 to ticks do
|
|
222 |
begin
|
|
223 |
X:= X + dX;
|
|
224 |
Y:= Y + dY;
|
351
|
225 |
tx:= hwRound(X);
|
|
226 |
ty:= hwRound(Y);
|
184
|
227 |
if ((ty and $FFFFFC00) = 0) and ((tx and $FFFFF800) = 0) then
|
|
228 |
begin
|
|
229 |
Land[ty, tx]:= 0;
|
|
230 |
ClearLandPixel(ty, tx);
|
|
231 |
end
|
|
232 |
end;
|
|
233 |
for t:= 0 to 7 do
|
|
234 |
{$include tunsetborder.inc}
|
|
235 |
nx:= nx - dY;
|
|
236 |
ny:= ny + dX;
|
|
237 |
end;
|
|
238 |
|
|
239 |
for i:= 0 to 7 do
|
|
240 |
begin
|
358
|
241 |
X:= nx - dX8;
|
|
242 |
Y:= ny - dY8;
|
184
|
243 |
for t:= -8 to ticks + 8 do
|
|
244 |
{$include tunsetborder.inc}
|
|
245 |
nx:= nx - dY;
|
|
246 |
ny:= ny + dX;
|
|
247 |
end;
|
|
248 |
|
|
249 |
if SDL_MustLock(LandSurface) then
|
|
250 |
SDL_UnlockSurface(LandSurface)
|
|
251 |
end;
|
|
252 |
|
|
253 |
|
|
254 |
end.
|