# HG changeset patch # User sheepluva # Date 1315620495 -7200 # Node ID 812be8a9692776777a69ad68bb1d5efb71862949 # Parent f9944a75b350241a60501e2b2440d9c2681ee171 actual rope fix for hogs getting stuck on walls diff -r f9944a75b350 -r 812be8a96927 hedgewars/GSHandlers.inc --- a/hedgewars/GSHandlers.inc Sat Sep 10 03:27:47 2011 +0200 +++ b/hedgewars/GSHandlers.inc Sat Sep 10 04:08:15 2011 +0200 @@ -1405,7 +1405,7 @@ var HHGear: PGear; len, tx, ty, nx, ny, ropeDx, ropeDy, mdX, mdY: hwFloat; - lx, ly: LongInt; + lx, ly, cd: LongInt; haveCollision, haveDivided: boolean; @@ -1446,16 +1446,30 @@ else if (Gear^.Message and gmRight <> 0) then HHGear^.dX := HHGear^.dX + _0_0002; - if not TestCollisionYwithGear(HHGear, 1) then - begin - HHGear^.dY := HHGear^.dY + cGravity; - if (GameFlags and gfMoreWind) <> 0 then HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density; - end; - // vector between hedgehog and rope attaching point ropeDx := HHGear^.X - Gear^.X; ropeDy := HHGear^.Y - Gear^.Y; + if not TestCollisionYwithGear(HHGear, 1) then + begin + + // depending on the rope vector we know which X-side to check for collision + // in order to find out if the hog can still be moved by gravity + if ropeDx.isNegative = RopeDy.IsNegative then + cd:= -1 + else + cd:= 1; + + // apply gravity if there is no obstacle + if not TestCollisionXwithGear(HHGear, cd) then + HHGear^.dY := HHGear^.dY + cGravity; + + if (GameFlags and gfMoreWind) <> 0 then + // apply wind if there's no obstacle + if not TestCollisionXwithGear(HHGear, hwSign(cWindSpeed)) then + HHGear^.dX := HHGear^.dX + cWindSpeed / HHGear^.Density; + end; + mdX := ropeDx + HHGear^.dX; mdY := ropeDy + HHGear^.dY; len := _1 / Distance(mdX, mdY);