340 |
340 |
341 UpdateLandTexture(tx, ddx, ty, ddy) |
341 UpdateLandTexture(tx, ddx, ty, ddy) |
342 end; |
342 end; |
343 |
343 |
344 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean; |
344 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean): boolean; |
345 var X, Y, bpp, h, w: LongInt; |
345 var X, Y, bpp, h, w, row, col, numFramesFirstCol: LongInt; |
346 p: PByteArray; |
346 p: PByteArray; |
347 Image: PSDL_Surface; |
347 Image: PSDL_Surface; |
348 begin |
348 begin |
|
349 numFramesFirstCol:= SpritesData[Obj].imageHeight div SpritesData[Obj].Height; |
|
350 |
349 TryDo(SpritesData[Obj].Surface <> nil, 'Assert SpritesData[Obj].Surface failed', true); |
351 TryDo(SpritesData[Obj].Surface <> nil, 'Assert SpritesData[Obj].Surface failed', true); |
350 Image:= SpritesData[Obj].Surface; |
352 Image:= SpritesData[Obj].Surface; |
351 w:= SpritesData[Obj].Width; |
353 w:= SpritesData[Obj].Width; |
352 h:= SpritesData[Obj].Height; |
354 h:= SpritesData[Obj].Height; |
|
355 row:= Frame mod numFramesFirstCol; |
|
356 col:= Frame div numFramesFirstCol; |
353 |
357 |
354 if SDL_MustLock(Image) then |
358 if SDL_MustLock(Image) then |
355 SDLTry(SDL_LockSurface(Image) >= 0, true); |
359 SDLTry(SDL_LockSurface(Image) >= 0, true); |
356 |
360 |
357 bpp:= Image^.format^.BytesPerPixel; |
361 bpp:= Image^.format^.BytesPerPixel; |
358 TryDo(bpp = 4, 'It should be 32 bpp sprite', true); |
362 TryDo(bpp = 4, 'It should be 32 bpp sprite', true); |
359 // Check that sprite fits free space |
363 // Check that sprite fits free space |
360 p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
364 //p:= @(PByteArray(Image^.pixels)^[Image^.pitch * ( col * h + row * w )]); |
|
365 p:= @(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 - 1 ]); |
361 case bpp of |
366 case bpp of |
362 4: for y:= 0 to Pred(h) do |
367 4: for y:= 0 to Pred(h) do |
363 begin |
368 begin |
364 for x:= 0 to Pred(w) do |
369 for x:= 0 to Pred(w) do |
365 if PLongword(@(p^[x * 4]))^ <> 0 then |
370 if PLongword(@(p^[x * 4]))^ <> 0 then |
384 SDL_UnlockSurface(Image); |
389 SDL_UnlockSurface(Image); |
385 exit |
390 exit |
386 end; |
391 end; |
387 |
392 |
388 // Checked, now place |
393 // Checked, now place |
389 p:= @(PByteArray(Image^.pixels)^[Image^.pitch * Frame * h]); |
394 p:= @(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 - 1 ]); |
390 case bpp of |
395 case bpp of |
391 4: for y:= 0 to Pred(h) do |
396 4: for y:= 0 to Pred(h) do |
392 begin |
397 begin |
393 for x:= 0 to Pred(w) do |
398 for x:= 0 to Pred(w) do |
394 if PLongword(@(p^[x * 4]))^ <> 0 then |
399 if PLongword(@(p^[x * 4]))^ <> 0 then |