serious anti wall sticking protection for hedgewars
authorsheepluva
Fri, 15 Jan 2016 13:18:40 +0100
changeset 11517 0e305b7153e6
parent 11516 2d26ad94a731
child 11518 d44d2ab7ce4a
serious anti wall sticking protection for hedgewars
hedgewars/uGearsHedgehog.pas
share/hedgewars/Data/Themes/Castle/LandBackTex.png
--- a/hedgewars/uGearsHedgehog.pas	Fri Jan 15 05:50:18 2016 +0100
+++ b/hedgewars/uGearsHedgehog.pas	Fri Jan 15 13:18:40 2016 +0100
@@ -873,6 +873,55 @@
 
 
 ////////////////////////////////////////////////////////////////////////////////
+procedure moveHedgehogOutOfWall(Gear: PGear);
+var
+    hx: hwFloat;
+    colly, collxl, collxr: boolean;
+begin
+colly:= (TestCollisionYwithGear(Gear, 1) <> 0);
+
+while colly do
+    begin
+    // don't use TestCollisionXwithXYShift, because we don't gears
+    // save real x-position
+    hx:= Gear^.X;
+
+    Gear^.X:= hx + _1;
+    collxl:= (TestCollisionX(Gear, -1) <> 0);
+
+    Gear^.X:= hx - _1;
+    collxr:= (TestCollisionX(Gear,  1) <> 0);
+
+    // restore original value
+    Gear^.X:= hx;
+
+    // do nothing if trapped between 2 walls
+    if collxl = collxr then
+        break;
+
+    // if we in a wall - fix that
+    if collxl then
+        begin
+        // check for obstacle
+        if (TestCollisionX(Gear,  1) <> 0) then
+            break;
+        Gear^.X:= Gear^.X + _1;
+        end
+    else
+        begin
+        // check for obstacle
+        if (TestCollisionX(Gear, -1) <> 0) then
+            break;
+        Gear^.X:= Gear^.X - _1;
+        end;
+
+        colly:= (TestCollisionYwithGear(Gear, 1) <> 0);
+        end;
+
+
+end;
+
+////////////////////////////////////////////////////////////////////////////////
 procedure doStepHedgehogMoving(Gear: PGear);
 var isFalling, isUnderwater: boolean;
     land: Word;
@@ -893,7 +942,15 @@
 if Gear^.dY.QWordValue > 8160437862 then
     Gear^.dY.QWordValue:= 8160437862;
 
-isFalling:= (Gear^.dY.isNegative) or (TestCollisionYKick(Gear, 1) = 0);
+isFalling:= (Gear^.dY.isNegative);
+if (not isFalling) then
+    begin
+    // make sure we're not just stuck in wall
+    moveHedgehogOutOfWall(Gear);
+    // test for floor/obstacle below
+    isFalling:= (TestCollisionYKick(Gear, 1) = 0);
+    end;
+
 if isFalling then
     begin
     land:= TestCollisionYKick(Gear, -1);
Binary file share/hedgewars/Data/Themes/Castle/LandBackTex.png has changed