# HG changeset patch # User sheepluva # Date 1452860320 -3600 # Node ID 0e305b7153e6593229888736fc8b95aae06987cd # Parent 2d26ad94a731a182176c1fd82ef1730f2d136eee serious anti wall sticking protection for hedgewars diff -r 2d26ad94a731 -r 0e305b7153e6 hedgewars/uGearsHedgehog.pas --- 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); diff -r 2d26ad94a731 -r 0e305b7153e6 share/hedgewars/Data/Themes/Castle/LandBackTex.png Binary file share/hedgewars/Data/Themes/Castle/LandBackTex.png has changed