49 procedure DrawIceBreak(x, y, iceRadius, iceHeight: Longint); |
49 procedure DrawIceBreak(x, y, iceRadius, iceHeight: Longint); |
50 function TryPlaceOnLandSimple(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean): boolean; inline; |
50 function TryPlaceOnLandSimple(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean): boolean; inline; |
51 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean; LandFlags: Word): boolean; inline; |
51 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace: boolean; LandFlags: Word): boolean; inline; |
52 function ForcePlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; LandFlags: Word; Tint: LongWord; Behind, flipHoriz, flipVert: boolean): boolean; inline; |
52 function ForcePlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; LandFlags: Word; Tint: LongWord; Behind, flipHoriz, flipVert: boolean): boolean; inline; |
53 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, outOfMap, force, behind, flipHoriz, flipVert: boolean; LandFlags: Word; Tint: LongWord): boolean; |
53 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, outOfMap, force, behind, flipHoriz, flipVert: boolean; LandFlags: Word; Tint: LongWord): boolean; |
|
54 procedure EraseLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; LandFlags: Word; eraseOnLFMatch, flipHoriz, flipVert: boolean); |
54 function GetPlaceCollisionTex(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): PTexture; |
55 function GetPlaceCollisionTex(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): PTexture; |
55 |
56 |
56 implementation |
57 implementation |
57 uses SDLh, uLandTexture, uTextures, uVariables, uUtils, uDebug, uScript; |
58 uses SDLh, uLandTexture, uTextures, uVariables, uUtils, uDebug, uScript; |
58 |
59 |
813 else if Obj = sprAmRubber then |
814 else if Obj = sprAmRubber then |
814 ScriptCall('onRubberPlacement', frame, cpX + w div 2, cpY + h div 2); |
815 ScriptCall('onRubberPlacement', frame, cpX + w div 2, cpY + h div 2); |
815 |
816 |
816 end; |
817 end; |
817 |
818 |
|
819 procedure EraseLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; LandFlags: Word; eraseOnLFMatch, flipHoriz, flipVert: boolean); |
|
820 var X, Y, bpp, h, w, row, col, gx, gy, numFramesFirstCol: LongInt; |
|
821 p: PByteArray; |
|
822 Image: PSDL_Surface; |
|
823 pixel: LongWord; |
|
824 begin |
|
825 numFramesFirstCol:= SpritesData[Obj].imageHeight div SpritesData[Obj].Height; |
|
826 |
|
827 TryDo(SpritesData[Obj].Surface <> nil, 'Assert SpritesData[Obj].Surface failed', true); |
|
828 |
|
829 Image:= SpritesData[Obj].Surface; |
|
830 w:= SpritesData[Obj].Width; |
|
831 h:= SpritesData[Obj].Height; |
|
832 if flipVert then flipSurface(Image, true); |
|
833 if flipHoriz then flipSurface(Image, false); |
|
834 row:= Frame mod numFramesFirstCol; |
|
835 col:= Frame div numFramesFirstCol; |
|
836 |
|
837 if SDL_MustLock(Image) then |
|
838 SDLTry(SDL_LockSurface(Image) >= 0, true); |
|
839 |
|
840 bpp:= Image^.format^.BytesPerPixel; |
|
841 TryDo(bpp = 4, 'It should be 32 bpp sprite', true); |
|
842 // Check that sprite fits free space |
|
843 p:= PByteArray(@(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ])); |
|
844 case bpp of |
|
845 4: for y:= 0 to Pred(h) do |
|
846 begin |
|
847 for x:= 0 to Pred(w) do |
|
848 if ((PLongword(@(p^[x * 4]))^) and AMask) <> 0 then |
|
849 if ((cpY + y) <= Longint(topY)) or ((cpY + y) >= LAND_HEIGHT) or |
|
850 ((cpX + x) <= Longint(leftX)) or ((cpX + x) >= Longint(rightX)) then |
|
851 begin |
|
852 if SDL_MustLock(Image) then |
|
853 SDL_UnlockSurface(Image); |
|
854 exit |
|
855 end; |
|
856 p:= PByteArray(@(p^[Image^.pitch])) |
|
857 end |
|
858 end; |
|
859 |
|
860 // Checked, now place |
|
861 p:= PByteArray(@(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ])); |
|
862 case bpp of |
|
863 4: for y:= 0 to Pred(h) do |
|
864 begin |
|
865 for x:= 0 to Pred(w) do |
|
866 if ((PLongword(@(p^[x * 4]))^) and AMask) <> 0 then |
|
867 begin |
|
868 if (cReducedQuality and rqBlurryLand) = 0 then |
|
869 begin |
|
870 gX:= cpX + x; |
|
871 gY:= cpY + y; |
|
872 end |
|
873 else |
|
874 begin |
|
875 gX:= (cpX + x) div 2; |
|
876 gY:= (cpY + y) div 2; |
|
877 end; |
|
878 if (not eraseOnLFMatch or (Land[cpY + y, cpX + x] and LandFlags <> 0)) and |
|
879 (PLongword(@(p^[x * 4]))^ and AMask <> 0) then |
|
880 begin |
|
881 LandPixels[gY, gX]:= 0; |
|
882 Land[cpY + y, cpX + x]:= 0 |
|
883 end |
|
884 end; |
|
885 p:= PByteArray(@(p^[Image^.pitch])); |
|
886 end; |
|
887 end; |
|
888 if SDL_MustLock(Image) then |
|
889 SDL_UnlockSurface(Image); |
|
890 |
|
891 if flipVert then flipSurface(Image, true); |
|
892 if flipHoriz then flipSurface(Image, false); |
|
893 |
|
894 x:= Max(cpX, leftX); |
|
895 w:= Min(cpX + Image^.w, LAND_WIDTH) - x; |
|
896 y:= Max(cpY, topY); |
|
897 h:= Min(cpY + Image^.h, LAND_HEIGHT) - y; |
|
898 UpdateLandTexture(x, w, y, h, true) |
|
899 end; |
|
900 |
818 function GetPlaceCollisionTex(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): PTexture; |
901 function GetPlaceCollisionTex(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): PTexture; |
819 var X, Y, bpp, h, w, row, col, numFramesFirstCol: LongInt; |
902 var X, Y, bpp, h, w, row, col, numFramesFirstCol: LongInt; |
820 p, pt: PLongWordArray; |
903 p, pt: PLongWordArray; |
821 Image, finalSurface: PSDL_Surface; |
904 Image, finalSurface: PSDL_Surface; |
822 begin |
905 begin |