hedgewars/uCollisions.pas
changeset 5896 9ce1cf4e5a32
parent 5834 f9944a75b350
child 5919 f737843dd331
equal deleted inserted replaced
5895:212d3b459658 5896:9ce1cf4e5a32
    48 function  TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
    48 function  TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
    49 
    49 
    50 function  TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
    50 function  TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
    51 function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
    51 function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
    52 
    52 
    53 function  calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean;
    53 function  TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
       
    54 function  CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): Boolean;
    54 
    55 
    55 implementation
    56 implementation
    56 uses uConsts, uLandGraphics, uVariables, uDebug, uGears;
    57 uses uConsts, uLandGraphics, uVariables, uDebug, uGears;
    57 
    58 
    58 type TCollisionEntry = record
    59 type TCollisionEntry = record
   347 else TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir);
   348 else TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir);
   348 Gear^.X:= Gear^.X - int2hwFloat(ShiftX);
   349 Gear^.X:= Gear^.X - int2hwFloat(ShiftX);
   349 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
   350 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
   350 end;
   351 end;
   351 
   352 
   352 
   353 function TestRectancleForObstacle(x1, y1, x2, y2: LongInt; landOnly: boolean): boolean;
   353 function calcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
   354 var x, y: LongInt;
       
   355     TestWord: LongWord;
       
   356 begin
       
   357 if landOnly then
       
   358     TestWord:= 255
       
   359 else
       
   360     TestWord:= 0;
       
   361 
       
   362 if x1 > x2 then
       
   363 begin
       
   364     x  := x1;
       
   365     x1 := x2;
       
   366     x2 := x;
       
   367 end;
       
   368 
       
   369 if y1 > y2 then
       
   370 begin
       
   371     y  := y1;
       
   372     y1 := y2;
       
   373     y2 := y;
       
   374 end;
       
   375 
       
   376 for y := y1 to y2 do
       
   377     for x := x1 to x2 do
       
   378         if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0)
       
   379           and (Land[y, x] > TestWord) then
       
   380             exit(true);
       
   381 
       
   382 TestRectancleForObstacle:= false
       
   383 end;
       
   384 
       
   385 function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
   354 var ldx, ldy, rdx, rdy: LongInt;
   386 var ldx, ldy, rdx, rdy: LongInt;
   355     i, j, mx, my, li, ri, jfr, jto, tmpo : ShortInt;
   387     i, j, mx, my, li, ri, jfr, jto, tmpo : ShortInt;
   356     tmpx, tmpy: LongWord;
   388     tmpx, tmpy: LongWord;
   357     dx, dy, s: hwFloat;
   389     dx, dy, s: hwFloat;
   358     offset: Array[0..7,0..1] of ShortInt;
   390     offset: Array[0..7,0..1] of ShortInt;