47 function DrawThickLine(X1, Y1, X2, Y2, radius: LongInt; color: Longword): Longword; |
47 function DrawThickLine(X1, Y1, X2, Y2, radius: LongInt; color: Longword): Longword; |
48 procedure DumpLandToLog(x, y, r: LongInt); |
48 procedure DumpLandToLog(x, y, r: LongInt); |
49 procedure DrawIceBreak(x, y, iceRadius, iceHeight: Longint); |
49 procedure DrawIceBreak(x, y, iceRadius, iceHeight: Longint); |
50 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean): boolean; inline; |
50 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean): boolean; inline; |
51 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean; LandFlags: Word): boolean; |
51 function TryPlaceOnLand(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt; doPlace, indestructible: boolean; LandFlags: Word): boolean; |
|
52 function GetPlaceCollisionTex(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): PTexture; |
52 |
53 |
53 implementation |
54 implementation |
54 uses SDLh, uLandTexture, uVariables, uUtils, uDebug; |
55 uses SDLh, uLandTexture, uTextures, uVariables, uUtils, uDebug; |
55 |
56 |
56 |
57 |
57 procedure calculatePixelsCoordinates(landX, landY: Longint; var pixelX, pixelY: Longint); inline; |
58 procedure calculatePixelsCoordinates(landX, landY: Longint; var pixelX, pixelY: Longint); inline; |
58 begin |
59 begin |
59 if (cReducedQuality and rqBlurryLand) = 0 then |
60 if (cReducedQuality and rqBlurryLand) = 0 then |
691 w:= Min(cpX + Image^.w, LAND_WIDTH) - x; |
692 w:= Min(cpX + Image^.w, LAND_WIDTH) - x; |
692 y:= Max(cpY, topY); |
693 y:= Max(cpY, topY); |
693 h:= Min(cpY + Image^.h, LAND_HEIGHT) - y; |
694 h:= Min(cpY + Image^.h, LAND_HEIGHT) - y; |
694 UpdateLandTexture(x, w, y, h, true) |
695 UpdateLandTexture(x, w, y, h, true) |
695 end; |
696 end; |
|
697 |
|
698 function GetPlaceCollisionTex(cpX, cpY: LongInt; Obj: TSprite; Frame: LongInt): PTexture; |
|
699 var X, Y, bpp, h, w, row, col, numFramesFirstCol: LongInt; |
|
700 p, pt: PByteArray; |
|
701 Image, finalSurface: PSDL_Surface; |
|
702 begin |
|
703 GetPlaceCollisionTex:= nil; |
|
704 numFramesFirstCol:= SpritesData[Obj].imageHeight div SpritesData[Obj].Height; |
|
705 |
|
706 TryDo(SpritesData[Obj].Surface <> nil, 'Assert SpritesData[Obj].Surface failed', true); |
|
707 Image:= SpritesData[Obj].Surface; |
|
708 w:= SpritesData[Obj].Width; |
|
709 h:= SpritesData[Obj].Height; |
|
710 row:= Frame mod numFramesFirstCol; |
|
711 col:= Frame div numFramesFirstCol; |
|
712 |
|
713 if SDL_MustLock(Image) then |
|
714 SDLTry(SDL_LockSurface(Image) >= 0, true); |
|
715 |
|
716 bpp:= Image^.format^.BytesPerPixel; |
|
717 TryDo(bpp = 4, 'It should be 32 bpp sprite', true); |
|
718 |
|
719 |
|
720 |
|
721 finalSurface:= SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, 32, RMask, GMask, BMask, AMask); |
|
722 |
|
723 TryDo(finalSurface <> nil, 'GetPlaceCollisionTex: fail to create surface', true); |
|
724 |
|
725 if SDL_MustLock(finalSurface) then |
|
726 SDLTry(SDL_LockSurface(finalSurface) >= 0, true); |
|
727 |
|
728 // draw on surface based on collisions |
|
729 p:= PByteArray(@(PByteArray(Image^.pixels)^[ Image^.pitch * row * h + col * w * 4 ])); |
|
730 pt:= PByteArray(@(PByteArray(finalSurface^.pixels)^)); |
|
731 |
|
732 case bpp of |
|
733 4: for y:= 0 to Pred(h) do |
|
734 begin |
|
735 for x:= 0 to Pred(w) do |
|
736 if (((PLongword(@(p^[x * 4]))^) and AMask) <> 0) |
|
737 and (((cpY + y) <= Longint(topY)) or ((cpY + y) >= LAND_HEIGHT) or |
|
738 ((cpX + x) <= Longint(leftX)) or ((cpX + x) >= Longint(rightX)) or (Land[cpY + y, cpX + x] <> 0)) then |
|
739 (PLongword(@(pt^[x * 4]))^):= cWhiteColor |
|
740 else |
|
741 (PLongword(@(pt^[x * 4]))^):= 0; |
|
742 p:= PByteArray(@(p^[Image^.pitch])); |
|
743 pt:= PByteArray(@(pt^[finalSurface^.pitch])); |
|
744 end; |
|
745 end; |
|
746 |
|
747 if SDL_MustLock(Image) then |
|
748 SDL_UnlockSurface(Image); |
|
749 |
|
750 if SDL_MustLock(finalSurface) then |
|
751 SDL_UnlockSurface(finalSurface); |
|
752 |
|
753 GetPlaceCollisionTex:= Surface2Tex(finalSurface, true); |
|
754 |
|
755 SDL_FreeSurface(finalSurface); |
|
756 end; |
|
757 |
696 |
758 |
697 function Despeckle(X, Y: LongInt): boolean; |
759 function Despeckle(X, Y: LongInt): boolean; |
698 var nx, ny, i, j, c, xx, yy: LongInt; |
760 var nx, ny, i, j, c, xx, yy: LongInt; |
699 pixelsweep: boolean; |
761 pixelsweep: boolean; |
700 |
762 |