give sea world edges some icegun love
authorsheepluva
Sun, 30 Nov 2014 02:41:49 +0100
changeset 10582 672e7028b1b6
parent 10580 17560eb73b4c
child 10583 8994cf0bb33e
give sea world edges some icegun love
hedgewars/uGearsHandlersMess.pas
hedgewars/uLandGraphics.pas
--- a/hedgewars/uGearsHandlersMess.pas	Sat Nov 29 15:30:33 2014 -0500
+++ b/hedgewars/uGearsHandlersMess.pas	Sun Nov 30 02:41:49 2014 +0100
@@ -5544,7 +5544,8 @@
         ndY:= -AngleCos(HHGear^.Angle) * _4;
         if (ndX <> dX) or (ndY <> dY) or
            ((Target.X <> NoPointX) and (Target.X and LAND_WIDTH_MASK = 0) and
-             (Target.Y and LAND_HEIGHT_MASK = 0) and ((Land[Target.Y, Target.X] = 0))) then
+             (Target.Y and LAND_HEIGHT_MASK = 0) and ((Land[Target.Y, Target.X] = 0)) and
+             (not CheckCoordInWater(Target.X, Target.Y))) then
             begin
             updateTarget(Gear, ndX, ndY);
             Timer := iceWaitCollision;
@@ -5568,10 +5569,15 @@
                         Power := GameTicks;
                         end
                     end
-                else if (Target.Y >= cWaterLine) or
-                        ((Target.X and LAND_WIDTH_MASK = 0) and
-                         (Target.Y+iceHeight+4 >= cWaterLine) and
-                         (Land[Target.Y, Target.X] = lfIce)) then
+                else if CheckCoordInWater(Target.X, Target.Y) or
+                        ((Target.X and LAND_WIDTH_MASK  = 0) and
+                         (Target.Y and LAND_HEIGHT_MASK = 0) and
+                         (Land[Target.Y, Target.X] = lfIce) and
+                         ((Target.Y+iceHeight+5 > cWaterLine) or
+                          ((WorldEdge = weSea) and
+                           ((Target.X+iceHeight+5 > LongInt(rightX)) or
+                            (Target.X-iceHeight-5 < LongInt(leftX)))))
+                         ) then
                     begin
                     if Timer = iceWaitCollision then
                         begin
@@ -5651,7 +5657,14 @@
                 if (Timer = iceCollideWithWater) and ((GameTicks - Power) > groundFreezingTime div 2) then
                     begin
                     PlaySound(sndHogFreeze);
-                    DrawIceBreak(Target.X, cWaterLine - iceHeight, iceRadius, iceHeight);
+                    if CheckCoordInWater(Target.X, Target.Y) then
+                        DrawIceBreak(Target.X, Target.Y, iceRadius, iceHeight)
+                    else if Target.Y+iceHeight+5 > cWaterLine then
+                        DrawIceBreak(Target.X, Target.Y+iceHeight+5, iceRadius, iceHeight)
+                    else if Target.X+iceHeight+5 > LongInt(rightX) then
+                        DrawIceBreak(Target.X+iceHeight+5, Target.Y, iceRadius, iceHeight)
+                    else
+                        DrawIceBreak(Target.X-iceHeight-5, Target.Y, iceRadius, iceHeight);
                     SetAllHHToActive;
                     Timer := iceWaitCollision;
                     end;
@@ -5689,7 +5702,7 @@
                                 end;
                 inc(Pos)
                 end
-            else if (t > 400) and ((gY > cWaterLine) or
+            else if (t > 400) and (CheckCoordInWater(gX, gY) or
                     (((gX and LAND_WIDTH_MASK = 0) and (gY and LAND_HEIGHT_MASK = 0))
                         and (Land[gY, gX] <> 0))) then
                 begin
--- a/hedgewars/uLandGraphics.pas	Sat Nov 29 15:30:33 2014 -0500
+++ b/hedgewars/uLandGraphics.pas	Sun Nov 30 02:41:49 2014 +0100
@@ -372,12 +372,48 @@
 
 procedure DrawIceBreak(x, y, iceRadius, iceHeight: Longint);
 var
-    i, j: integer;
+    i, j, iceL, iceR, IceT, iceB: LongInt;
     landRect: TSDL_Rect;
 begin
-for i := min(max(x - iceRadius, 0), LAND_WIDTH - 1) to min(max(x + iceRadius, 0), LAND_WIDTH - 1) do
+// figure out bottom/left/right/top coords of ice to draw
+
+// determine absolute limits first
+iceT:= 0;
+iceB:= min(cWaterLine, LAND_HEIGHT - 1);
+
+iceL:= 0;
+iceR:= LAND_WIDTH - 1;
+
+if WorldEdge <> weNone then
+    begin
+    iceL:= max(leftX,  iceL);
+    iceR:= min(rightX, iceR);
+    end;
+
+// adjust based on location but without violating absolute limits
+if y >= cWaterLine then
     begin
-    for j := min(max(y, 0), LAND_HEIGHT - 1) to min(max(y + iceHeight, 0), LAND_HEIGHT - 1) do
+    iceL:= max(x - iceRadius, iceL);
+    iceR:= min(x + iceRadius, iceR);
+    iceT:= max(cWaterLine - iceHeight, iceT);
+    end
+else {if WorldEdge = weSea then}
+    begin
+    iceT:= max(y - iceRadius, iceT);
+    iceB:= min(y + iceRadius, iceB);
+    if x <= leftX then
+        iceR:= min(leftX + iceHeight, iceR)
+    else {if x >= rightX then}
+        iceL:= max(LongInt(rightX) - iceHeight, iceL);
+    end;
+
+// don't continue if all ice is outside land array
+if (iceL > iceR) or (iceT > iceB) then
+    exit();
+
+for i := iceL to iceR do
+    begin
+    for j := iceT to iceB do
         begin
         if Land[j, i] = 0 then
             begin
@@ -389,10 +425,12 @@
             end;
         end;
     end;
-landRect.x := min(max(x - iceRadius, 0), LAND_WIDTH - 1);
-landRect.y := min(max(y, 0), LAND_HEIGHT - 1);
-landRect.w := min(2*iceRadius, LAND_WIDTH - landRect.x - 1);
-landRect.h := min(iceHeight, LAND_HEIGHT - landRect.y - 1);
+
+landRect.x := iceL;
+landRect.y := iceT;
+landRect.w := iceR - IceL + 1;
+landRect.h := iceB - iceT + 1;
+
 UpdateLandTexture(landRect.x, landRect.w, landRect.y, landRect.h, true);
 end;