hedgewars/uCollisions.pas
branchhedgeroid
changeset 5932 5164d17b6374
parent 5919 f737843dd331
child 6081 537bbd5c1a62
equal deleted inserted replaced
5828:667fb58d7f18 5932:5164d17b6374
    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 if (hasBorder and ((y1 < 0) or (x1 < 0) or (x2 > LAND_WIDTH))) then
       
   377     exit(true);
       
   378 
       
   379 for y := y1 to y2 do
       
   380     for x := x1 to x2 do
       
   381         if ((y and LAND_HEIGHT_MASK) = 0) and ((x and LAND_WIDTH_MASK) = 0)
       
   382           and (Land[y, x] > TestWord) then
       
   383             exit(true);
       
   384 
       
   385 TestRectancleForObstacle:= false
       
   386 end;
       
   387 
       
   388 function CalcSlopeTangent(Gear: PGear; collisionX, collisionY: LongInt; var outDeltaX, outDeltaY: LongInt; TestWord: LongWord): boolean;
   354 var ldx, ldy, rdx, rdy: LongInt;
   389 var ldx, ldy, rdx, rdy: LongInt;
   355     i, j, mx, my, li, ri, jfr, jto, tmpo : ShortInt;
   390     i, j, mx, my, li, ri, jfr, jto, tmpo : ShortInt;
   356     tmpx, tmpy: LongWord;
   391     tmpx, tmpy: LongWord;
   357     dx, dy, s: hwFloat;
   392     dx, dy, s: hwFloat;
   358     offset: Array[0..7,0..1] of ShortInt;
   393     offset: Array[0..7,0..1] of ShortInt;