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