hedgewars/uCollisions.pas
changeset 5896 9ce1cf4e5a32
parent 5834 f9944a75b350
child 5919 f737843dd331
--- a/hedgewars/uCollisions.pas	Tue Sep 13 21:25:13 2011 -0400
+++ b/hedgewars/uCollisions.pas	Wed Sep 14 17:17:50 2011 +0200
@@ -50,7 +50,8 @@
 function  TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
 function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
 
-function  calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean;
+function  TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
+function  CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean;
 
 implementation
 uses uConsts, uLandGraphics, uVariables, uDebug, uGears;
@@ -349,8 +350,39 @@
 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
 end;
 
+function TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
+var x, y: LongInt;
+    TestWord: LongWord;
+begin
+if landOnly then
+    TestWord:= 255
+else
+    TestWord:= 0;
 
-function calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
+if x1 > x2 then
+begin
+    x  := x1;
+    x1 := x2;
+    x2 := x;
+end;
+
+if y1 > y2 then
+begin
+    y  := y1;
+    y1 := y2;
+    y2 := y;
+end;
+
+for y := y1 to y2 do
+    for x := x1 to x2 do
+        if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0)
+          and (Land[y, x] > TestWord) then
+            exit(true);
+
+TestRectancleForObstacle:= false
+end;
+
+function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
 var ldx, ldy, rdx, rdy: LongInt;
     i, j, mx, my, li, ri, jfr, jto, tmpo : ShortInt;
     tmpx, tmpy: LongWord;