hedgewars/uLandGraphics.pas
changeset 10677 328f526c95b6
parent 10674 fddbab2eecea
child 10864 9cf20f487ee9
equal deleted inserted replaced
10676:7111b4a46b5c 10677:328f526c95b6
   797 
   797 
   798 end;
   798 end;
   799 
   799 
   800 function GetPlaceCollisionTex(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): PTexture;
   800 function GetPlaceCollisionTex(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): PTexture;
   801 var X, Y, bpp, h, w, row, col, numFramesFirstCol: LongInt;
   801 var X, Y, bpp, h, w, row, col, numFramesFirstCol: LongInt;
   802     p, pt: PByteArray;
   802     p, pt: PLongWordArray;
   803     Image, finalSurface: PSDL_Surface;
   803     Image, finalSurface: PSDL_Surface;
   804 begin
   804 begin
   805 GetPlaceCollisionTex:= nil;
   805 GetPlaceCollisionTex:= nil;
   806 numFramesFirstCol:= SpritesData[Obj].imageHeight div SpritesData[Obj].Height;
   806 numFramesFirstCol:= SpritesData[Obj].imageHeight div SpritesData[Obj].Height;
   807 
   807 
   825 TryDo(finalSurface <> nil, 'GetPlaceCollisionTex: fail to create surface', true);
   825 TryDo(finalSurface <> nil, 'GetPlaceCollisionTex: fail to create surface', true);
   826 
   826 
   827 if SDL_MustLock(finalSurface) then
   827 if SDL_MustLock(finalSurface) then
   828     SDLTry(SDL_LockSurface(finalSurface) >= 0, true);
   828     SDLTry(SDL_LockSurface(finalSurface) >= 0, true);
   829 
   829 
   830 // draw on surface based on collisions
   830 p:= PLongWordArray(@(PLongWordArray(Image^.pixels)^[ (Image^.pitch div 4) * row * h + col * w ]));
   831 p:= PByteArray(@(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ]));
   831 pt:= PLongWordArray(finalSurface^.pixels);
   832 pt:= PByteArray(@(PByteArray(finalSurface^.pixels)^));
   832 
   833 
   833 for y:= 0 to Pred(h) do
   834 case bpp of
   834     begin
   835     4: for y:= 0 to Pred(h) do
   835     for x:= 0 to Pred(w) do
   836         begin
   836         if ((p^[x] and AMask) <> 0)
   837         for x:= 0 to Pred(w) do
   837             and (((cpY + y) < Longint(topY)) or ((cpY + y) >= LAND_HEIGHT) or
   838             if (((PLongword(@(p^[x * 4]))^) and AMask) <> 0)
   838             ((cpX + x) < Longint(leftX)) or ((cpX + x) > Longint(rightX)) or (Land[cpY + y, cpX + x] <> 0)) then
   839                 and (((cpY + y) <= Longint(topY)) or ((cpY + y) >= LAND_HEIGHT) or
   839                 pt^[x]:= cWhiteColor
   840                    ((cpX + x) <= Longint(leftX)) or ((cpX + x) >= Longint(rightX)) or (Land[cpY + y, cpX + x] <> 0)) then
   840         else
   841                     (PLongword(@(pt^[x * 4]))^):= cWhiteColor
   841             (pt^[x]):= cWhiteColor and (not AMask);
   842             else
   842     p:= PLongWordArray(@(p^[Image^.pitch div 4]));
   843                 (PLongword(@(pt^[x * 4]))^):= 0;
   843     pt:= PLongWordArray(@(pt^[finalSurface^.pitch div 4]));
   844         p:= PByteArray(@(p^[Image^.pitch]));
       
   845         pt:= PByteArray(@(pt^[finalSurface^.pitch]));
       
   846         end;
       
   847     end;
   844     end;
   848 
   845 
   849 if SDL_MustLock(Image) then
   846 if SDL_MustLock(Image) then
   850     SDL_UnlockSurface(Image);
   847     SDL_UnlockSurface(Image);
   851 
   848