Bounce off gears at bouncy world edge only if they move towards it
authorWuzzy <Wuzzy2@mail.ru>
Sun, 13 Jan 2019 15:47:14 +0100
changeset 14563 ca9c632db2cf
parent 14562 af22a14c6a23
child 14564 599f136d4f32
Bounce off gears at bouncy world edge only if they move towards it
hedgewars/uGearsUtils.pas
--- a/hedgewars/uGearsUtils.pas	Sun Jan 13 05:00:14 2019 +0100
+++ b/hedgewars/uGearsUtils.pas	Sun Jan 13 15:47:14 2019 +0100
@@ -1746,7 +1746,7 @@
 Trying to make the checks a little broader than on first pass to catch things that don't move normally.
 *)
 function WorldWrap(var Gear: PGear): boolean;
-//var tdx: hwFloat;
+var bounced: boolean;
 begin
 WorldWrap:= false;
 if WorldEdge = weNone then exit(false);
@@ -1763,19 +1763,22 @@
         end
     else if WorldEdge = weBounce then
         begin
-        if (hwRound(Gear^.X) - Gear^.Radius < leftX) then
+        bounced:= false;
+        if (hwRound(Gear^.X) - Gear^.Radius < leftX) and (hwSign(Gear^.dX) = -1) and (not isZero(Gear^.dX)) then
             begin
             LeftImpactTimer:= 333;
             Gear^.dX.isNegative:= false;
-            Gear^.X:= int2hwfloat(leftX + Gear^.Radius)
+            Gear^.X:= int2hwfloat(leftX + Gear^.Radius);
+            bounced:= true;
             end
-        else
+        else if (hwRound(Gear^.X) - Gear^.Radius > rightX) and (hwSign(Gear^.dX) = 1) and (not isZero(Gear^.dX)) then
             begin
             RightImpactTimer:= 333;
             Gear^.dX.isNegative:= true;
-            Gear^.X:= int2hwfloat(rightX-Gear^.Radius)
+            Gear^.X:= int2hwfloat(rightX-Gear^.Radius);
+            bounced:= true;
             end;
-        if (Gear^.Radius > 2) and (Gear^.dX.QWordValue > _0_001.QWordValue) then
+        if (bounced) and (Gear^.Radius > 2) and (Gear^.dX.QWordValue > _0_001.QWordValue) then
             AddBounceEffectForGear(Gear);
         end{
     else if WorldEdge = weSea then