hedgewars/uGearsHandlersRope.pas
changeset 13978 818969052920
parent 13961 2568fa516733
child 14287 6015b74eea55
--- a/hedgewars/uGearsHandlersRope.pas	Thu Oct 25 20:40:02 2018 +0300
+++ b/hedgewars/uGearsHandlersRope.pas	Thu Oct 25 23:39:54 2018 +0200
@@ -214,12 +214,12 @@
 
     if ((Gear^.Message and gmDown) <> 0) and (Gear^.Elasticity < Gear^.Friction) then
         if not ((TestCollisionXwithXYShift(HHGear, _2*hwSign(ropeDx), 0, hwSign(ropeDx), true) <> 0)
-        or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, 1*hwSign(ropeDy), hwSign(ropeDy)) <> 0))) then
+        or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, hwSign(ropeDy), hwSign(ropeDy)) <> 0))) then
             Gear^.Elasticity := Gear^.Elasticity + _1_2;
 
     if ((Gear^.Message and gmUp) <> 0) and (Gear^.Elasticity > _30) then
         if not ((TestCollisionXwithXYShift(HHGear, -_2*hwSign(ropeDx), 0, -hwSign(ropeDx), true) <> 0)
-        or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, 1*-hwSign(ropeDy), -hwSign(ropeDy)) <> 0))) then
+        or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, -hwSign(ropeDy), -hwSign(ropeDy)) <> 0))) then
             Gear^.Elasticity := Gear^.Elasticity - _1_2;
 
     HHGear^.X := Gear^.X + mdX * Gear^.Elasticity;
@@ -227,8 +227,6 @@
 
     HHGear^.dX := HHGear^.X - tx;
     HHGear^.dY := HHGear^.Y - ty;
-    ////
-
 
     haveDivided := false;
     // check whether rope needs dividing
@@ -429,7 +427,6 @@
     HHGear: PGear;
     tx, ty, tt: hwFloat;
 begin
-    
     Gear^.X := Gear^.X - Gear^.dX;
     Gear^.Y := Gear^.Y - Gear^.dY;
     Gear^.Elasticity := Gear^.Elasticity + _1;
@@ -466,6 +463,11 @@
         Gear^.X := Gear^.X + HHGear^.dX;
         Gear^.Y := Gear^.Y + HHGear^.dY;
 
+        // hedgehog can teleport up to 5 pixels upwards when sliding,
+        // so we have to give up the maintained rope length
+        // after doStepHedgehogMoving() call and recalculate
+        // it based on the gear and current hedgehog positions
+        Gear^.Elasticity:= int2hwFloat(hwRound(Distance(Gear^.X - HHGear^.X, Gear^.Y - HHGear^.Y) + _0_001));
 
         tt := Gear^.Elasticity;
         tx := _0;
@@ -478,6 +480,7 @@
                 Gear^.Y := Gear^.Y + ty;
                 Gear^.Elasticity := tt;
                 Gear^.doStep := @doStepRopeWork;
+
                 PlaySound(sndRopeAttach);
                 with HHGear^ do
                     begin
@@ -486,8 +489,6 @@
                     end;
 
                 RopeRemoveFromAmmo(Gear, HHGear);
-
-                tt := _0;
                 exit
                 end;
             tx := tx + Gear^.dX + Gear^.dX;