Not sticky rope
authorunc0rr
Sun, 02 Sep 2012 19:58:56 +0400
changeset 7652 db731c523653
parent 7651 4cd85eebc54b
child 7653 6dda2562f692
Not sticky rope
hedgewars/uGearsHandlersRope.pas
--- a/hedgewars/uGearsHandlersRope.pas	Sun Sep 02 11:44:59 2012 -0400
+++ b/hedgewars/uGearsHandlersRope.pas	Sun Sep 02 19:58:56 2012 +0400
@@ -101,7 +101,7 @@
     len, tx, ty, nx, ny, ropeDx, ropeDy, mdX, mdY, sDx, sDy: hwFloat;
     i, lx, ly, cd: LongInt;
     haveCollision,
-    haveDivided: boolean;
+    haveDivided, bx, by: boolean;
 
 begin
     if GameTicks mod 8 <> 0 then exit;
@@ -180,23 +180,29 @@
     HHGear^.dX := Gear^.X + mdX * Gear^.Elasticity - tx;
     HHGear^.dY := Gear^.Y + mdY * Gear^.Elasticity - ty;
 
-    sDx:= HHGear^.dX / 8;
-    sDy:= HHGear^.dY / 8;
+    sDx:= HHGear^.dX / 4;
+    sDy:= HHGear^.dY / 4;
 
     HHGear^.X:= tx;
     HHGear^.Y:= ty;
 
     i:= 0;
-    while not ((i = 8)
-        or TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX))
-        or (TestCollisionYwithGear(HHGear, hwSign(HHGear^.dY)) <> 0)) do
+    bx:= TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX));
+    by:= TestCollisionYwithGear(HHGear, hwSign(HHGear^.dY)) <> 0;
+    while not ((i = 4)
+        or bx
+        or by) do
         begin
         inc(i);
         HHGear^.X:= HHGear^.X + sDx;
         HHGear^.Y:= HHGear^.Y + sDy;
+        bx:= TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX));
+        by:= TestCollisionYwithGear(HHGear, hwSign(HHGear^.dY)) <> 0;
         end;
     ////
 
+    if not bx then HHGear^.dX:= HHGear^.X - tx;
+    if not by then HHGear^.dY:= HHGear^.Y - ty;
 
     haveDivided := false;
     // check whether rope needs dividing