author | unc0rr |
Wed, 02 May 2007 21:37:08 +0000 | |
changeset 504 | 13b6ebc53627 |
parent 495 | 62c1c2b4414c |
child 505 | fcba7d7aea0d |
permissions | -rw-r--r-- |
393 | 1 |
(* |
2 |
* Hedgewars, a worms-like game |
|
3 |
* Copyright (c) 2005-2007 Andrey Korotaev <unC0Rr@gmail.com> |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or modify |
|
6 |
* it under the terms of the GNU General Public License as published by |
|
7 |
* the Free Software Foundation; version 2 of the License |
|
8 |
* |
|
9 |
* This program is distributed in the hope that it will be useful, |
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
* GNU General Public License for more details. |
|
13 |
* |
|
14 |
* You should have received a copy of the GNU General Public License |
|
15 |
* along with this program; if not, write to the Free Software |
|
16 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
|
17 |
*) |
|
18 |
||
184 | 19 |
unit uLandGraphics; |
20 |
interface |
|
409 | 21 |
uses uFloat, uConsts; |
345 | 22 |
{$INCLUDE options.inc} |
184 | 23 |
|
24 |
type PRangeArray = ^TRangeArray; |
|
25 |
TRangeArray = array[0..31] of record |
|
371 | 26 |
Left, Right: LongInt; |
184 | 27 |
end; |
28 |
||
371 | 29 |
procedure DrawExplosion(X, Y, Radius: LongInt); |
30 |
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte); |
|
31 |
procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt); |
|
32 |
procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword); |
|
504
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
33 |
procedure ChangeRoundInLand(X, Y, Radius: LongInt; Delta: LongInt); |
184 | 34 |
|
409 | 35 |
function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): boolean; |
36 |
||
184 | 37 |
implementation |
409 | 38 |
uses SDLh, uMisc, uLand; |
184 | 39 |
|
371 | 40 |
procedure FillCircleLines(x, y, dx, dy: LongInt; Value: Longword); |
41 |
var i: LongInt; |
|
184 | 42 |
begin |
43 |
if ((y + dy) and $FFFFFC00) = 0 then |
|
44 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do Land[y + dy, i]:= Value; |
|
45 |
if ((y - dy) and $FFFFFC00) = 0 then |
|
46 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do Land[y - dy, i]:= Value; |
|
47 |
if ((y + dx) and $FFFFFC00) = 0 then |
|
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 |
|
50 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do Land[y - dx, i]:= Value; |
|
51 |
end; |
|
52 |
||
504
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
53 |
procedure ChangeCircleLines(x, y, dx, dy: LongInt; Delta: LongInt); |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
54 |
var i: LongInt; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
55 |
begin |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
56 |
if ((y + dy) and $FFFFFC00) = 0 then |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
57 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do inc(Land[y + dy, i], Delta); |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
58 |
if ((y - dy) and $FFFFFC00) = 0 then |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
59 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do inc(Land[y - dy, i], Delta); |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
60 |
if ((y + dx) and $FFFFFC00) = 0 then |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
61 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do inc(Land[y + dx, i], Delta); |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
62 |
if ((y - dx) and $FFFFFC00) = 0 then |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
63 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do inc(Land[y - dx, i], Delta); |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
64 |
end; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
65 |
|
371 | 66 |
procedure FillRoundInLand(X, Y, Radius: LongInt; Value: Longword); |
67 |
var dx, dy, d: LongInt; |
|
184 | 68 |
begin |
69 |
dx:= 0; |
|
70 |
dy:= Radius; |
|
71 |
d:= 3 - 2 * Radius; |
|
72 |
while (dx < dy) do |
|
73 |
begin |
|
74 |
FillCircleLines(x, y, dx, dy, Value); |
|
75 |
if (d < 0) |
|
76 |
then d:= d + 4 * dx + 6 |
|
77 |
else begin |
|
78 |
d:= d + 4 * (dx - dy) + 10; |
|
79 |
dec(dy) |
|
80 |
end; |
|
81 |
inc(dx) |
|
82 |
end; |
|
83 |
if (dx = dy) then FillCircleLines(x, y, dx, dy, Value); |
|
84 |
end; |
|
85 |
||
504
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
86 |
procedure ChangeRoundInLand(X, Y, Radius: LongInt; Delta: LongInt); |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
87 |
var dx, dy, d: LongInt; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
88 |
begin |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
89 |
dx:= 0; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
90 |
dy:= Radius; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
91 |
d:= 3 - 2 * Radius; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
92 |
while (dx < dy) do |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
93 |
begin |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
94 |
ChangeCircleLines(x, y, dx, dy, Delta); |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
95 |
if (d < 0) |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
96 |
then d:= d + 4 * dx + 6 |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
97 |
else begin |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
98 |
d:= d + 4 * (dx - dy) + 10; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
99 |
dec(dy) |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
100 |
end; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
101 |
inc(dx) |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
102 |
end; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
103 |
if (dx = dy) then ChangeCircleLines(x, y, dx, dy, Delta); |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
104 |
end; |
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
105 |
|
13b6ebc53627
Fix collision info artifacts in Land array when two objects intersect
unc0rr
parents:
495
diff
changeset
|
106 |
|
371 | 107 |
procedure ClearLandPixel(y, x: LongInt); |
184 | 108 |
var p: PByteArray; |
109 |
begin |
|
351 | 110 |
p:= @PByteArray(LandSurface^.pixels)^[LandSurface^.pitch * y]; |
111 |
case LandSurface^.format^.BytesPerPixel of |
|
112 |
2: PWord(@(p^[x * 2]))^:= 0; |
|
184 | 113 |
3: begin |
351 | 114 |
p^[x * 3 + 0]:= 0; |
115 |
p^[x * 3 + 1]:= 0; |
|
116 |
p^[x * 3 + 2]:= 0; |
|
184 | 117 |
end; |
351 | 118 |
4: PLongword(@(p^[x * 4]))^:= 0; |
184 | 119 |
end |
120 |
end; |
|
121 |
||
371 | 122 |
procedure SetLandPixel(y, x: LongInt); |
184 | 123 |
var p: PByteArray; |
124 |
begin |
|
351 | 125 |
p:= @PByteArray(LandSurface^.pixels)^[LandSurface^.pitch * y]; |
126 |
case LandSurface^.format^.BytesPerPixel of |
|
127 |
2: PWord(@(p^[x * 2]))^:= cExplosionBorderColor; |
|
184 | 128 |
3: begin |
351 | 129 |
p^[x * 3 + 0]:= cExplosionBorderColor and $FF; |
130 |
p^[x * 3 + 1]:= (cExplosionBorderColor shr 8) and $FF; |
|
131 |
p^[x * 3 + 2]:= cExplosionBorderColor shr 16; |
|
184 | 132 |
end; |
351 | 133 |
4: PLongword(@(p^[x * 4]))^:= cExplosionBorderColor; |
184 | 134 |
end |
135 |
end; |
|
136 |
||
371 | 137 |
procedure FillLandCircleLines0(x, y, dx, dy: LongInt); |
138 |
var i: LongInt; |
|
184 | 139 |
begin |
140 |
if ((y + dy) and $FFFFFC00) = 0 then |
|
141 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do ClearLandPixel(y + dy, i); |
|
142 |
if ((y - dy) and $FFFFFC00) = 0 then |
|
143 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do ClearLandPixel(y - dy, i); |
|
144 |
if ((y + dx) and $FFFFFC00) = 0 then |
|
145 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do ClearLandPixel(y + dx, i); |
|
146 |
if ((y - dx) and $FFFFFC00) = 0 then |
|
147 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do ClearLandPixel(y - dx, i); |
|
148 |
end; |
|
149 |
||
371 | 150 |
procedure FillLandCircleLinesEBC(x, y, dx, dy: LongInt); |
151 |
var i: LongInt; |
|
184 | 152 |
begin |
153 |
if ((y + dy) and $FFFFFC00) = 0 then |
|
154 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do |
|
155 |
if Land[y + dy, i] = COLOR_LAND then SetLandPixel(y + dy, i); |
|
156 |
if ((y - dy) and $FFFFFC00) = 0 then |
|
157 |
for i:= max(x - dx, 0) to min(x + dx, 2047) do |
|
158 |
if Land[y - dy, i] = COLOR_LAND then SetLandPixel(y - dy, i); |
|
159 |
if ((y + dx) and $FFFFFC00) = 0 then |
|
160 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do |
|
161 |
if Land[y + dx, i] = COLOR_LAND then SetLandPixel(y + dx, i); |
|
162 |
if ((y - dx) and $FFFFFC00) = 0 then |
|
163 |
for i:= max(x - dy, 0) to min(x + dy, 2047) do |
|
164 |
if Land[y - dx, i] = COLOR_LAND then SetLandPixel(y - dx, i); |
|
165 |
end; |
|
166 |
||
371 | 167 |
procedure DrawExplosion(X, Y, Radius: LongInt); |
168 |
var dx, dy, d: LongInt; |
|
184 | 169 |
begin |
170 |
FillRoundInLand(X, Y, Radius, 0); |
|
171 |
||
172 |
if SDL_MustLock(LandSurface) then |
|
173 |
SDLTry(SDL_LockSurface(LandSurface) >= 0, true); |
|
174 |
||
175 |
dx:= 0; |
|
176 |
dy:= Radius; |
|
177 |
d:= 3 - 2 * Radius; |
|
178 |
while (dx < dy) do |
|
179 |
begin |
|
180 |
FillLandCircleLines0(x, y, dx, dy); |
|
181 |
if (d < 0) |
|
182 |
then d:= d + 4 * dx + 6 |
|
183 |
else begin |
|
184 |
d:= d + 4 * (dx - dy) + 10; |
|
185 |
dec(dy) |
|
186 |
end; |
|
187 |
inc(dx) |
|
188 |
end; |
|
189 |
if (dx = dy) then FillLandCircleLines0(x, y, dx, dy); |
|
190 |
inc(Radius, 4); |
|
191 |
dx:= 0; |
|
192 |
dy:= Radius; |
|
193 |
d:= 3 - 2 * Radius; |
|
194 |
while (dx < dy) do |
|
195 |
begin |
|
196 |
FillLandCircleLinesEBC(x, y, dx, dy); |
|
197 |
if (d < 0) |
|
198 |
then d:= d + 4 * dx + 6 |
|
199 |
else begin |
|
200 |
d:= d + 4 * (dx - dy) + 10; |
|
201 |
dec(dy) |
|
202 |
end; |
|
203 |
inc(dx) |
|
204 |
end; |
|
351 | 205 |
if (dx = dy) then FillLandCircleLinesEBC(x, y, dx, dy); |
206 |
||
184 | 207 |
if SDL_MustLock(LandSurface) then |
208 |
SDL_UnlockSurface(LandSurface); |
|
209 |
end; |
|
210 |
||
371 | 211 |
procedure DrawHLinesExplosions(ar: PRangeArray; Radius: LongInt; y, dY: LongInt; Count: Byte); |
184 | 212 |
var tx, ty, i: LongInt; |
213 |
begin |
|
214 |
if SDL_MustLock(LandSurface) then |
|
215 |
SDL_LockSurface(LandSurface); |
|
216 |
||
217 |
for i:= 0 to Pred(Count) do |
|
218 |
begin |
|
188 | 219 |
for ty:= max(y - Radius, 0) to min(y + Radius, 1023) do |
351 | 220 |
for tx:= max(0, ar^[i].Left - Radius) to min(2047, ar^[i].Right + Radius) do |
188 | 221 |
ClearLandPixel(ty, tx); |
184 | 222 |
inc(y, dY) |
223 |
end; |
|
224 |
||
225 |
inc(Radius, 4); |
|
351 | 226 |
dec(y, Count * dY); |
184 | 227 |
|
228 |
for i:= 0 to Pred(Count) do |
|
229 |
begin |
|
188 | 230 |
for ty:= max(y - Radius, 0) to min(y + Radius, 1023) do |
351 | 231 |
for tx:= max(0, ar^[i].Left - Radius) to min(2047, ar^[i].Right + Radius) do |
188 | 232 |
if Land[ty, tx] = $FFFFFF then |
233 |
SetLandPixel(ty, tx); |
|
184 | 234 |
inc(y, dY) |
235 |
end; |
|
236 |
||
237 |
if SDL_MustLock(LandSurface) then |
|
238 |
SDL_UnlockSurface(LandSurface); |
|
239 |
end; |
|
240 |
||
241 |
// |
|
242 |
// - (dX, dY) - direction, vector of length = 0.5 |
|
243 |
// |
|
371 | 244 |
procedure DrawTunnel(X, Y, dX, dY: hwFloat; ticks, HalfWidth: LongInt); |
358 | 245 |
var nx, ny, dX8, dY8: hwFloat; |
184 | 246 |
i, t, tx, ty: Longint; |
247 |
begin // (-dY, dX) is (dX, dY) rotated by PI/2 |
|
248 |
if SDL_MustLock(LandSurface) then |
|
249 |
SDL_LockSurface(LandSurface); |
|
250 |
||
251 |
nx:= X + dY * (HalfWidth + 8); |
|
252 |
ny:= Y - dX * (HalfWidth + 8); |
|
253 |
||
358 | 254 |
dX8:= dX * 8; |
255 |
dY8:= dY * 8; |
|
184 | 256 |
for i:= 0 to 7 do |
257 |
begin |
|
358 | 258 |
X:= nx - dX8; |
259 |
Y:= ny - dY8; |
|
184 | 260 |
for t:= -8 to ticks + 8 do |
261 |
{$include tunsetborder.inc} |
|
262 |
nx:= nx - dY; |
|
263 |
ny:= ny + dX; |
|
264 |
end; |
|
265 |
||
266 |
for i:= -HalfWidth to HalfWidth do |
|
267 |
begin |
|
358 | 268 |
X:= nx - dX8; |
269 |
Y:= ny - dY8; |
|
184 | 270 |
for t:= 0 to 7 do |
271 |
{$include tunsetborder.inc} |
|
272 |
X:= nx; |
|
273 |
Y:= ny; |
|
274 |
for t:= 0 to ticks do |
|
275 |
begin |
|
276 |
X:= X + dX; |
|
277 |
Y:= Y + dY; |
|
351 | 278 |
tx:= hwRound(X); |
279 |
ty:= hwRound(Y); |
|
184 | 280 |
if ((ty and $FFFFFC00) = 0) and ((tx and $FFFFF800) = 0) then |
281 |
begin |
|
282 |
Land[ty, tx]:= 0; |
|
283 |
ClearLandPixel(ty, tx); |
|
284 |
end |
|
285 |
end; |
|
286 |
for t:= 0 to 7 do |
|
287 |
{$include tunsetborder.inc} |
|
288 |
nx:= nx - dY; |
|
289 |
ny:= ny + dX; |
|
290 |
end; |
|
291 |
||
292 |
for i:= 0 to 7 do |
|
293 |
begin |
|
358 | 294 |
X:= nx - dX8; |
295 |
Y:= ny - dY8; |
|
184 | 296 |
for t:= -8 to ticks + 8 do |
297 |
{$include tunsetborder.inc} |
|
298 |
nx:= nx - dY; |
|
299 |
ny:= ny + dX; |
|
300 |
end; |
|
301 |
||
302 |
if SDL_MustLock(LandSurface) then |
|
303 |
SDL_UnlockSurface(LandSurface) |
|
304 |
end; |
|
305 |
||
409 | 306 |
function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): boolean; |
495 | 307 |
var X, Y, bpp, h, w: LongInt; |
409 | 308 |
p: PByteArray; |
309 |
r, rr: TSDL_Rect; |
|
310 |
Image: PSDL_Surface; |
|
311 |
begin |
|
312 |
Image:= SpritesData[Obj].Surface; |
|
313 |
w:= SpritesData[Obj].Width; |
|
314 |
h:= SpritesData[Obj].Height; |
|
315 |
||
316 |
if SDL_MustLock(Image) then |
|
317 |
SDLTry(SDL_LockSurface(Image) >= 0, true); |
|
318 |
||
319 |
bpp:= Image^.format^.BytesPerPixel; |
|
320 |
TryDo(bpp <> 1, 'We don''t work with 8 bit surfaces', true); |
|
321 |
// Check that sprites fits free space |
|
322 |
p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
|
323 |
case bpp of |
|
324 |
2: for y:= 0 to Pred(h) do |
|
325 |
begin |
|
326 |
for x:= 0 to Pred(w) do |
|
327 |
if PWord(@(p^[x * 2]))^ <> 0 then |
|
328 |
if (((cpY + y) and $FFFFFC00) <> 0) or |
|
329 |
(((cpX + x) and $FFFFF800) <> 0) or |
|
330 |
(Land[cpY + y, cpX + x] <> 0) then |
|
331 |
begin |
|
332 |
if SDL_MustLock(Image) then |
|
333 |
SDL_UnlockSurface(Image); |
|
334 |
exit(false) |
|
335 |
end; |
|
336 |
p:= @(p^[Image^.pitch]); |
|
337 |
end; |
|
338 |
3: for y:= 0 to Pred(h) do |
|
339 |
begin |
|
340 |
for x:= 0 to Pred(w) do |
|
341 |
if (p^[x * 3 + 0] <> 0) |
|
342 |
or (p^[x * 3 + 1] <> 0) |
|
343 |
or (p^[x * 3 + 2] <> 0) then |
|
344 |
if (((cpY + y) and $FFFFFC00) <> 0) or |
|
345 |
(((cpX + x) and $FFFFF800) <> 0) or |
|
346 |
(Land[cpY + y, cpX + x] <> 0) then |
|
347 |
begin |
|
348 |
if SDL_MustLock(Image) then |
|
349 |
SDL_UnlockSurface(Image); |
|
350 |
exit(false) |
|
351 |
end; |
|
352 |
p:= @(p^[Image^.pitch]); |
|
353 |
end; |
|
354 |
4: for y:= 0 to Pred(h) do |
|
355 |
begin |
|
356 |
for x:= 0 to Pred(w) do |
|
357 |
if PLongword(@(p^[x * 4]))^ <> 0 then |
|
358 |
if (((cpY + y) and $FFFFFC00) <> 0) or |
|
359 |
(((cpX + x) and $FFFFF800) <> 0) or |
|
360 |
(Land[cpY + y, cpX + x] <> 0) then |
|
361 |
begin |
|
362 |
if SDL_MustLock(Image) then |
|
363 |
SDL_UnlockSurface(Image); |
|
364 |
exit(false) |
|
365 |
end; |
|
366 |
p:= @(p^[Image^.pitch]); |
|
367 |
end; |
|
368 |
end; |
|
369 |
||
370 |
// Checked, now place |
|
371 |
p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
|
372 |
case bpp of |
|
373 |
2: for y:= 0 to Pred(h) do |
|
374 |
begin |
|
375 |
for x:= 0 to Pred(w) do |
|
376 |
if PWord(@(p^[x * 2]))^ <> 0 then Land[cpY + y, cpX + x]:= COLOR_LAND; |
|
377 |
p:= @(p^[Image^.pitch]); |
|
378 |
end; |
|
379 |
3: for y:= 0 to Pred(h) do |
|
380 |
begin |
|
381 |
for x:= 0 to Pred(w) do |
|
382 |
if (p^[x * 3 + 0] <> 0) |
|
383 |
or (p^[x * 3 + 1] <> 0) |
|
384 |
or (p^[x * 3 + 2] <> 0) then Land[cpY + y, cpX + x]:= COLOR_LAND; |
|
385 |
p:= @(p^[Image^.pitch]); |
|
386 |
end; |
|
387 |
4: for y:= 0 to Pred(h) do |
|
388 |
begin |
|
389 |
for x:= 0 to Pred(w) do |
|
390 |
if PLongword(@(p^[x * 4]))^ <> 0 then Land[cpY + y, cpX + x]:= COLOR_LAND; |
|
391 |
p:= @(p^[Image^.pitch]); |
|
392 |
end; |
|
393 |
end; |
|
394 |
if SDL_MustLock(Image) then |
|
395 |
SDL_UnlockSurface(Image); |
|
396 |
||
397 |
// Draw sprite on Land surface |
|
398 |
r.x:= 0; |
|
399 |
r.y:= SpritesData[Obj].Height * Frame; |
|
400 |
r.w:= SpritesData[Obj].Width; |
|
401 |
r.h:= SpritesData[Obj].Height; |
|
402 |
rr.x:= cpX; |
|
403 |
rr.y:= cpY; |
|
404 |
SDL_UpperBlit(Image, @r, LandSurface, @rr); |
|
405 |
||
406 |
TryPlaceOnLand:= true |
|
407 |
end; |
|
408 |
||
184 | 409 |
|
410 |
end. |