279 |
279 |
280 UpdateLandTexture(0, 1024) |
280 UpdateLandTexture(0, 1024) |
281 end; |
281 end; |
282 |
282 |
283 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean; |
283 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean; |
284 (*var X, Y, bpp, h, w: LongInt; |
284 var X, Y, bpp, h, w: LongInt; |
285 p: PByteArray; |
285 p: PByteArray; |
286 r, rr: TSDL_Rect; |
286 r, rr: TSDL_Rect; |
287 Image: PSDL_Surface;*) |
287 Image: PSDL_Surface; |
288 begin |
288 begin |
289 (*Image:= SpritesData[Obj].Surface; |
289 TryDo(SpritesData[Obj].Surface <> nil, 'Assert SpritesData[Obj].Surface failed', true); |
|
290 Image:= SpritesData[Obj].Surface; |
290 w:= SpritesData[Obj].Width; |
291 w:= SpritesData[Obj].Width; |
291 h:= SpritesData[Obj].Height; |
292 h:= SpritesData[Obj].Height; |
292 |
293 |
293 if SDL_MustLock(Image) then |
294 if SDL_MustLock(Image) then |
294 SDLTry(SDL_LockSurface(Image) >= 0, true); |
295 SDLTry(SDL_LockSurface(Image) >= 0, true); |
295 |
296 |
296 bpp:= Image^.format^.BytesPerPixel; |
297 bpp:= Image^.format^.BytesPerPixel; |
297 TryDo(bpp <> 1, 'We don''t work with 8 bit surfaces', true); |
298 TryDo(bpp = 4, 'It should be 32 bpp sprite', true); |
298 // Check that sprites fits free space |
299 // Check that sprite fits free space |
299 p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
300 p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
300 case bpp of |
301 case bpp of |
301 2: for y:= 0 to Pred(h) do |
|
302 begin |
|
303 for x:= 0 to Pred(w) do |
|
304 if PWord(@(p^[x * 2]))^ <> 0 then |
|
305 if (((cpY + y) and $FFFFFC00) <> 0) or |
|
306 (((cpX + x) and $FFFFF800) <> 0) or |
|
307 (Land[cpY + y, cpX + x] <> 0) then |
|
308 begin |
|
309 if SDL_MustLock(Image) then |
|
310 SDL_UnlockSurface(Image); |
|
311 exit(false) |
|
312 end; |
|
313 p:= @(p^[Image^.pitch]); |
|
314 end; |
|
315 3: for y:= 0 to Pred(h) do |
|
316 begin |
|
317 for x:= 0 to Pred(w) do |
|
318 if (p^[x * 3 + 0] <> 0) |
|
319 or (p^[x * 3 + 1] <> 0) |
|
320 or (p^[x * 3 + 2] <> 0) then |
|
321 if (((cpY + y) and $FFFFFC00) <> 0) or |
|
322 (((cpX + x) and $FFFFF800) <> 0) or |
|
323 (Land[cpY + y, cpX + x] <> 0) then |
|
324 begin |
|
325 if SDL_MustLock(Image) then |
|
326 SDL_UnlockSurface(Image); |
|
327 exit(false) |
|
328 end; |
|
329 p:= @(p^[Image^.pitch]); |
|
330 end; |
|
331 4: for y:= 0 to Pred(h) do |
302 4: for y:= 0 to Pred(h) do |
332 begin |
303 begin |
333 for x:= 0 to Pred(w) do |
304 for x:= 0 to Pred(w) do |
334 if PLongword(@(p^[x * 4]))^ <> 0 then |
305 if PLongword(@(p^[x * 4]))^ <> 0 then |
335 if (((cpY + y) and $FFFFFC00) <> 0) or |
306 if (((cpY + y) and $FFFFFC00) <> 0) or |
343 p:= @(p^[Image^.pitch]); |
314 p:= @(p^[Image^.pitch]); |
344 end; |
315 end; |
345 end; |
316 end; |
346 |
317 |
347 TryPlaceOnLand:= true; |
318 TryPlaceOnLand:= true; |
348 if not doPlace then exit; |
319 if not doPlace then |
|
320 begin |
|
321 if SDL_MustLock(Image) then |
|
322 SDL_UnlockSurface(Image); |
|
323 exit |
|
324 end; |
349 |
325 |
350 // Checked, now place |
326 // Checked, now place |
351 p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
327 p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
352 case bpp of |
328 case bpp of |
353 2: for y:= 0 to Pred(h) do |
|
354 begin |
|
355 for x:= 0 to Pred(w) do |
|
356 if PWord(@(p^[x * 2]))^ <> 0 then Land[cpY + y, cpX + x]:= COLOR_LAND; |
|
357 p:= @(p^[Image^.pitch]); |
|
358 end; |
|
359 3: for y:= 0 to Pred(h) do |
|
360 begin |
|
361 for x:= 0 to Pred(w) do |
|
362 if (p^[x * 3 + 0] <> 0) |
|
363 or (p^[x * 3 + 1] <> 0) |
|
364 or (p^[x * 3 + 2] <> 0) then Land[cpY + y, cpX + x]:= COLOR_LAND; |
|
365 p:= @(p^[Image^.pitch]); |
|
366 end; |
|
367 4: for y:= 0 to Pred(h) do |
329 4: for y:= 0 to Pred(h) do |
368 begin |
330 begin |
369 for x:= 0 to Pred(w) do |
331 for x:= 0 to Pred(w) do |
370 if PLongword(@(p^[x * 4]))^ <> 0 then Land[cpY + y, cpX + x]:= COLOR_LAND; |
332 if PLongword(@(p^[x * 4]))^ <> 0 then |
|
333 begin |
|
334 Land[cpY + y, cpX + x]:= COLOR_LAND; |
|
335 LandPixels[cpY + y, cpX + x]:= PLongword(@(p^[x * 4]))^ |
|
336 end; |
371 p:= @(p^[Image^.pitch]); |
337 p:= @(p^[Image^.pitch]); |
372 end; |
338 end; |
373 end; |
339 end; |
374 if SDL_MustLock(Image) then |
340 if SDL_MustLock(Image) then |
375 SDL_UnlockSurface(Image); |
341 SDL_UnlockSurface(Image); |
376 |
342 |
377 // Draw sprite on Land surface |
343 y:= max(cpY, 0); |
378 r.x:= 0; |
344 h:= min(cpY + Image^.h, 1023) - y; |
379 r.y:= SpritesData[Obj].Height * Frame; |
345 addfilelog(inttostr(y) + ' <<<<<<<<>>>>>>>> '+inttostr(h)); |
380 r.w:= SpritesData[Obj].Width; |
346 UpdateLandTexture(y, h) |
381 r.h:= SpritesData[Obj].Height; |
|
382 rr.x:= cpX; |
|
383 rr.y:= cpY; |
|
384 SDL_UpperBlit(Image, @r, LandSurface, @rr)*) |
|
385 end; |
347 end; |
386 |
348 |
387 |
349 |
388 end. |
350 end. |