adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
authorsheepluva
Fri, 05 Dec 2014 02:19:30 +0100
changeset 10626 2562797ab3cf
parent 10625 125e120165aa
child 10627 07ff179b0d97
adjust position of world edges (at 150 px away from outmost land collision, or less if land array ends earlier)
hedgewars/uConsts.pas
hedgewars/uLand.pas
hedgewars/uLandUtils.pas
hedgewars/uStore.pas
--- a/hedgewars/uConsts.pas	Thu Dec 04 20:15:03 2014 +0100
+++ b/hedgewars/uConsts.pas	Fri Dec 05 02:19:30 2014 +0100
@@ -319,6 +319,7 @@
     kSystemSoundID_Vibrate = $00000FFF;
 
     cMinPlayWidth = 200;
+    cWorldEdgeDist = 150;
 
 implementation
 
--- a/hedgewars/uLand.pas	Thu Dec 04 20:15:03 2014 +0100
+++ b/hedgewars/uLand.pas	Fri Dec 05 02:19:30 2014 +0100
@@ -665,6 +665,9 @@
     end;
 
 PrettifyLandAlpha();
+
+InitWorldEdges();
+
 end;
 
 procedure GenPreview(out Preview: TPreview);
--- a/hedgewars/uLandUtils.pas	Thu Dec 04 20:15:03 2014 +0100
+++ b/hedgewars/uLandUtils.pas	Fri Dec 05 02:19:30 2014 +0100
@@ -2,9 +2,10 @@
 interface
 
 procedure ResizeLand(width, height: LongWord);
+procedure InitWorldEdges();
 
 implementation
-uses uUtils, uConsts, uVariables;
+uses uUtils, uConsts, uVariables, uTypes;
 
 procedure ResizeLand(width, height: LongWord);
 var potW, potH: LongInt;
@@ -31,4 +32,56 @@
     end;
 end;
 
+procedure InitWorldEdges();
+var cy, cx, lx, ly: LongInt;
+    found: boolean;
+begin
+playHeight:= LAND_HEIGHT;
+topY:= 0;
+
+lx:= LongInt(LAND_WIDTH) - 1;
+
+if WorldEdge = weNone then
+    begin
+    playWidth:= LAND_WIDTH;
+    leftX := 0;
+    rightX:= lx;
+    EXIT;
+    end;
+
+ly:= LongInt(LAND_HEIGHT) - 1;
+
+// find most left land pixels and set leftX accordingly
+found:= false;
+for cx:= 0 to lx do
+    begin
+    for cy:= ly downto 0 do
+        if Land[cy, cx] <> 0 then
+            begin
+            leftX:= max(0, cx - cWorldEdgeDist);
+            // break out of both loops
+            found:= true;
+            break;
+            end;
+    if found then break;
+    end;
+
+// find most right land pixels and set rightX accordingly
+found:= false;
+for cx:= lx downto 0 do
+    begin
+    for cy:= ly downto 0 do
+        if Land[cy, cx] <> 0 then
+            begin
+            rightX:= min(lx, cx + cWorldEdgeDist);
+            // break out of both loops
+            found:= true;
+            break;
+            end;
+    if found then break;
+    end;
+
+playWidth := rightX + 1 - leftX;
+end;
+
 end.
--- a/hedgewars/uStore.pas	Thu Dec 04 20:15:03 2014 +0100
+++ b/hedgewars/uStore.pas	Fri Dec 05 02:19:30 2014 +0100
@@ -97,7 +97,6 @@
 procedure InitZoom(zoom: real);
 begin
     SetScale(zoom);
-    UpdateViewLimits();
 end;
 
 function WriteInRect(Surface: PSDL_Surface; X, Y: LongInt; Color: LongWord; Font: THWFont; s: PChar): TSDL_Rect;