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);
|
101
|
10 |
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: integer; y, dY: integer; Count: Byte);
|
107
|
11 |
procedure DrawTunnel(X, Y, dX, dY: Double; ticks, HalfWidth: integer);
|
54
|
12 |
procedure FillRoundInLand(X, Y, Radius: integer; Value: Longword);
|
|
13 |
|
|
14 |
implementation
|
64
|
15 |
uses SDLh, uStore, uMisc, uLand, uConsts;
|
54
|
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);
|
101
|
51 |
var p: PByteArray;
|
57
|
52 |
begin
|
101
|
53 |
p:= @PByteArray(LandSurface.pixels)^[LandSurface.pitch*y];
|
57
|
54 |
case LandSurface.format.BytesPerPixel of
|
|
55 |
1: ;// not supported
|
101
|
56 |
2: PWord(@p[x * 2])^:= 0;
|
57
|
57 |
3: begin
|
101
|
58 |
p[x * 3 + 0]:= 0;
|
|
59 |
p[x * 3 + 1]:= 0;
|
|
60 |
p[x * 3 + 2]:= 0;
|
57
|
61 |
end;
|
101
|
62 |
4: PLongword(@p[x * 4])^:= 0;
|
|
63 |
end
|
57
|
64 |
end;
|
|
65 |
|
|
66 |
procedure SetLandPixel(y, x: integer);
|
101
|
67 |
var p: PByteArray;
|
57
|
68 |
begin
|
101
|
69 |
p:= @PByteArray(LandSurface.pixels)^[LandSurface.pitch*y];
|
57
|
70 |
case LandSurface.format.BytesPerPixel of
|
|
71 |
1: ;// not supported
|
101
|
72 |
2: PWord(@p[x * 2])^:= cExplosionBorderColor;
|
57
|
73 |
3: begin
|
101
|
74 |
p[x * 3 + 0]:= cExplosionBorderColor and $FF;
|
|
75 |
p[x * 3 + 1]:= (cExplosionBorderColor shr 8) and $FF;
|
|
76 |
p[x * 3 + 2]:= cExplosionBorderColor shr 16;
|
57
|
77 |
end;
|
101
|
78 |
4: PLongword(@p[x * 4])^:= cExplosionBorderColor;
|
|
79 |
end
|
57
|
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
|
64
|
100 |
if Land[y + dy, i] = COLOR_LAND then SetLandPixel(y + dy, i);
|
57
|
101 |
if ((y - dy) and $FFFFFC00) = 0 then
|
|
102 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do
|
64
|
103 |
if Land[y - dy, i] = COLOR_LAND then SetLandPixel(y - dy, i);
|
57
|
104 |
if ((y + dx) and $FFFFFC00) = 0 then
|
|
105 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do
|
64
|
106 |
if Land[y + dx, i] = COLOR_LAND then SetLandPixel(y + dx, i);
|
57
|
107 |
if ((y - dx) and $FFFFFC00) = 0 then
|
|
108 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do
|
64
|
109 |
if Land[y - dx, i] = COLOR_LAND then SetLandPixel(y - dx, i);
|
57
|
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 |
|
101
|
156 |
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: integer; y, dY: integer; Count: Byte);
|
109
|
157 |
var tx, ty, i: LongInt;
|
54
|
158 |
begin
|
|
159 |
if SDL_MustLock(LandSurface) then
|
|
160 |
SDL_LockSurface(LandSurface);
|
|
161 |
|
|
162 |
for i:= 0 to Pred(Count) do
|
|
163 |
begin
|
101
|
164 |
for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
165 |
for tx:= max(0, ar[i].Left - Radius) to min(2047, ar[i].Right + Radius) do
|
|
166 |
ClearLandPixel(y + ty, tx);
|
54
|
167 |
inc(y, dY)
|
|
168 |
end;
|
|
169 |
|
|
170 |
inc(Radius, 4);
|
|
171 |
dec(y, Count*dY);
|
|
172 |
|
|
173 |
for i:= 0 to Pred(Count) do
|
|
174 |
begin
|
101
|
175 |
for ty:= max(-Radius, -y) to min(Radius, 1023 - y) do
|
|
176 |
for tx:= max(0, ar[i].Left - Radius) to min(2047, ar[i].Right + Radius) do
|
|
177 |
if Land[y + ty, tx] = $FFFFFF then
|
|
178 |
SetLandPixel(y + ty, tx);
|
54
|
179 |
inc(y, dY)
|
|
180 |
end;
|
|
181 |
|
|
182 |
if SDL_MustLock(LandSurface) then
|
|
183 |
SDL_UnlockSurface(LandSurface);
|
|
184 |
end;
|
|
185 |
|
|
186 |
//
|
|
187 |
// - (dX, dY) - direction, vector of length = 0.5
|
|
188 |
//
|
107
|
189 |
procedure DrawTunnel(X, Y, dX, dY: Double; ticks, HalfWidth: integer);
|
|
190 |
var nx, ny: Double;
|
109
|
191 |
i, t, tx, ty: Longint;
|
|
192 |
begin // (-dY, dX) is (dX, dY) rotated by PI/2
|
54
|
193 |
if SDL_MustLock(LandSurface) then
|
|
194 |
SDL_LockSurface(LandSurface);
|
|
195 |
|
|
196 |
nx:= X + dY * (HalfWidth + 8);
|
|
197 |
ny:= Y - dX * (HalfWidth + 8);
|
|
198 |
|
|
199 |
for i:= 0 to 7 do
|
|
200 |
begin
|
|
201 |
X:= nx - 8 * dX;
|
|
202 |
Y:= ny - 8 * dY;
|
|
203 |
for t:= -8 to ticks + 8 do
|
|
204 |
{$include tunsetborder.inc}
|
|
205 |
nx:= nx - dY;
|
|
206 |
ny:= ny + dX;
|
|
207 |
end;
|
|
208 |
|
|
209 |
for i:= -HalfWidth to HalfWidth do
|
|
210 |
begin
|
|
211 |
X:= nx - dX * 8;
|
|
212 |
Y:= ny - dY * 8;
|
|
213 |
for t:= 0 to 7 do
|
|
214 |
{$include tunsetborder.inc}
|
|
215 |
X:= nx;
|
|
216 |
Y:= ny;
|
|
217 |
for t:= 0 to ticks do
|
|
218 |
begin
|
|
219 |
X:= X + dX;
|
|
220 |
Y:= Y + dY;
|
|
221 |
tx:= round(X);
|
|
222 |
ty:= round(Y);
|
|
223 |
if ((ty and $FFFFFC00) = 0) and ((tx and $FFFFF800) = 0) then
|
|
224 |
begin
|
|
225 |
Land[ty, tx]:= 0;
|
101
|
226 |
ClearLandPixel(ty, tx);
|
54
|
227 |
end
|
|
228 |
end;
|
|
229 |
for t:= 0 to 7 do
|
|
230 |
{$include tunsetborder.inc}
|
|
231 |
nx:= nx - dY;
|
|
232 |
ny:= ny + dX;
|
|
233 |
end;
|
|
234 |
|
|
235 |
for i:= 0 to 7 do
|
|
236 |
begin
|
|
237 |
X:= nx - 8 * dX;
|
|
238 |
Y:= ny - 8 * dY;
|
|
239 |
for t:= -8 to ticks + 8 do
|
|
240 |
{$include tunsetborder.inc}
|
|
241 |
nx:= nx - dY;
|
|
242 |
ny:= ny + dX;
|
|
243 |
end;
|
|
244 |
|
|
245 |
if SDL_MustLock(LandSurface) then
|
|
246 |
SDL_UnlockSurface(LandSurface)
|
|
247 |
end;
|
|
248 |
|
|
249 |
|
|
250 |
end.
|