hedgewars/uCollisions.pas
changeset 7272 71df899c4163
parent 7270 93e92e82d5c8
child 7305 b242e91a92a9
--- a/hedgewars/uCollisions.pas	Sat Jun 23 21:37:47 2012 -0400
+++ b/hedgewars/uCollisions.pas	Sat Jun 23 22:39:00 2012 -0400
@@ -138,18 +138,11 @@
 var x, y, i: LongInt;
     TestWord: LongWord;
 begin
-if Gear^.IntersectGear <> nil then
-    with Gear^ do
-        if (hwRound(IntersectGear^.X) + IntersectGear^.Radius < hwRound(X) - Radius)
-        or (hwRound(IntersectGear^.X) - IntersectGear^.Radius > hwRound(X) + Radius) then
-            begin
-            IntersectGear:= nil;
-            TestWord:= 0
-            end
-        else
-            TestWord:= 255
-else 
-    TestWord:= 0;
+// Special case to emulate the old intersect gear clearing, but with a bit of slop for pixel overlap
+if (Gear^.CollisionMask = $FF7F) and (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) and
+    ((hwRound(Gear^.Hedgehog^.Gear^.X) + Gear^.Hedgehog^.Gear^.Radius + 4 < hwRound(Gear^.X) - Gear^.Radius) or
+     (hwRound(Gear^.Hedgehog^.Gear^.X) - Gear^.Hedgehog^.Gear^.Radius - 4 > hwRound(Gear^.X) + Gear^.Radius)) then
+    Gear^.CollisionMask:= $FFFF;
 
 x:= hwRound(Gear^.X);
 if Dir < 0 then
@@ -164,7 +157,7 @@
     i:= y + Gear^.Radius * 2 - 2;
     repeat
         if (y and LAND_HEIGHT_MASK) = 0 then
-            if Land[y, x] > TestWord then
+            if Land[y, x] and Gear^.CollisionMask <> 0 then
                 exit;
         inc(y)
     until (y > i);
@@ -176,18 +169,11 @@
 var x, y, i: LongInt;
     TestWord: LongWord;
 begin
-if Gear^.IntersectGear <> nil then
-    with Gear^ do
-        if (hwRound(IntersectGear^.Y) + IntersectGear^.Radius < hwRound(Y) - Radius) or
-            (hwRound(IntersectGear^.Y) - IntersectGear^.Radius > hwRound(Y) + Radius) then
-                begin
-                IntersectGear:= nil;
-                TestWord:= 0
-                end
-        else
-            TestWord:= 255
-else
-    TestWord:= 0;
+// Special case to emulate the old intersect gear clearing, but with a bit of slop for pixel overlap
+if (Gear^.CollisionMask = $FF7F) and (Gear^.Hedgehog <> nil) and (Gear^.Hedgehog^.Gear <> nil) and
+    ((hwRound(Gear^.Hedgehog^.Gear^.Y) + Gear^.Hedgehog^.Gear^.Radius + 4 < hwRound(Gear^.Y) - Gear^.Radius) or
+     (hwRound(Gear^.Hedgehog^.Gear^.Y) - Gear^.Hedgehog^.Gear^.Radius - 4 > hwRound(Gear^.Y) + Gear^.Radius)) then
+    Gear^.CollisionMask:= $FFFF;
 
 y:= hwRound(Gear^.Y);
 if Dir < 0 then
@@ -201,12 +187,12 @@
     i:= x + Gear^.Radius * 2 - 2;
     repeat
         if (x and LAND_WIDTH_MASK) = 0 then
-            if Land[y, x] > TestWord then
-            begin
+            if Land[y, x] and Gear^.CollisionMask <> 0 then
+                begin
                 TestCollisionYwithGear:= Land[y, x];
                 exit;
-            end;
-     inc(x)
+                end;
+        inc(x)
     until (x > i);
     end;
 TestCollisionYwithGear:= 0