make wrapping nicer when there's collision
authornemo
Sun, 13 Oct 2013 13:14:32 -0400
changeset 9526 2fd51591b260
parent 9524 0a52c1dd9400
child 9528 9351e96990ae
make wrapping nicer when there's collision
hedgewars/uGearsHandlersMess.pas
hedgewars/uGearsHandlersRope.pas
hedgewars/uGearsHedgehog.pas
--- a/hedgewars/uGearsHandlersMess.pas	Fri Oct 11 13:06:04 2013 -0400
+++ b/hedgewars/uGearsHandlersMess.pas	Sun Oct 13 13:14:32 2013 -0400
@@ -280,11 +280,17 @@
 var
     isFalling: boolean;
     //tmp: QWord;
-    tdX, tdY: hwFloat;
+    tX, tdX, tdY: hwFloat;
     collV, collH: LongInt;
     land: word;
 begin
-    WorldWrap(Gear);
+    tX:= Gear^.X;
+    if WorldWrap(Gear) and (WorldEdge = weWrap) and (Gear^.AdvBounce <> 0) and
+      (TestCollisionXwithGear(Gear, 1) or TestCollisionXwithGear(Gear, -1))  then
+        begin
+        Gear^.X:= tX;
+        Gear^.dX.isNegative:= (hwRound(tX) > leftX+Gear^.Radius*2)
+        end;
 
     // clip velocity at 2 - over 1 per pixel, but really shouldn't cause many actual problems.
     if Gear^.dX.Round > 2 then
--- a/hedgewars/uGearsHandlersRope.pas	Fri Oct 11 13:06:04 2013 -0400
+++ b/hedgewars/uGearsHandlersRope.pas	Sun Oct 13 13:14:32 2013 -0400
@@ -31,9 +31,17 @@
 procedure doStepRopeAfterAttack(Gear: PGear);
 var 
     HHGear: PGear;
+    tX:     hwFloat;
 begin
     HHGear := Gear^.Hedgehog^.Gear;
-    WorldWrap(HHGear);
+    tX:= HHGear^.X;
+    if WorldWrap(HHGear) and (WorldEdge = weWrap) and 
+       (TestCollisionXwithGear(HHGear, 1) or TestCollisionXwithGear(HHGear, -1))  then
+        begin
+        HHGear^.X:= tX;
+        HHGear^.dX.isNegative:= (hwRound(tX) > leftX+HHGear^.Radius*2)
+        end;
+
     if (HHGear^.Hedgehog^.CurAmmoType = amParachute) and (HHGear^.dY > _0_39) then
         begin
         DeleteGear(Gear);
@@ -117,8 +125,20 @@
 
     HHGear := Gear^.Hedgehog^.Gear;
 
-    if ((HHGear^.State and gstHHDriven) = 0) or WorldWrap(HHGear)
-       or (CheckGearDrowning(HHGear)) or (Gear^.PortalCounter <> 0) then
+    tX:= HHGear^.X;
+    if WorldWrap(HHGear) and (WorldEdge = weWrap) and 
+       (TestCollisionXwithGear(HHGear, 1) or TestCollisionXwithGear(HHGear, -1))  then
+        begin
+        PlaySound(sndRopeRelease);
+        RopeDeleteMe(Gear, HHGear);
+        HHGear^.X:= tX;
+        HHGear^.dX.isNegative:= (hwRound(tX) > leftX+HHGear^.Radius*2);
+        exit
+        end;
+
+    tX:= HHGear^.X;
+    if ((HHGear^.State and gstHHDriven) = 0) or
+        (CheckGearDrowning(HHGear)) or (Gear^.PortalCounter <> 0) then
         begin
         PlaySound(sndRopeRelease);
         RopeDeleteMe(Gear, HHGear);
--- a/hedgewars/uGearsHedgehog.pas	Fri Oct 11 13:06:04 2013 -0400
+++ b/hedgewars/uGearsHedgehog.pas	Sun Oct 13 13:14:32 2013 -0400
@@ -1275,10 +1275,20 @@
 
 ////////////////////////////////////////////////////////////////////////////////
 procedure doStepHedgehog(Gear: PGear);
+var tX: hwFloat;
 begin
-if WorldWrap(Gear) and (WorldEdge <> weBounce) and 
-  (Gear = CurrentHedgehog^.Gear) and (CurAmmoGear <> nil) and (CurAmmoGear^.Kind =gtRope) then
-   CurAmmoGear^.PortalCounter:= 1;
+tX:= Gear^.X;
+if WorldWrap(Gear) then
+    begin
+    if (WorldEdge <> weBounce) and (Gear = CurrentHedgehog^.Gear) and 
+       (CurAmmoGear <> nil) and (CurAmmoGear^.Kind =gtRope) then
+       CurAmmoGear^.PortalCounter:= 1;
+    if (WorldEdge = weWrap) and (TestCollisionXwithGear(Gear, 1) or TestCollisionXwithGear(Gear, -1))  then
+        begin
+        Gear^.X:= tX;
+        Gear^.dX.isNegative:= (hwRound(tX) > leftX+Gear^.Radius*2)
+        end
+    end;
 
 CheckSum:= CheckSum xor Gear^.Hedgehog^.BotLevel;
 if (Gear^.Message and gmDestroy) <> 0 then