hedgewars/uCollisions.pas
changeset 5830 ea4d1fe665d7
parent 5750 6bbf7aee2cdf
child 5834 f9944a75b350
equal deleted inserted replaced
5829:3ec95dc2b249 5830:ea4d1fe665d7
    41 function  TestCollisionXwithGear(Gear: PGear; Dir: LongInt): boolean;
    41 function  TestCollisionXwithGear(Gear: PGear; Dir: LongInt): boolean;
    42 function  TestCollisionYwithGear(Gear: PGear; Dir: LongInt): boolean;
    42 function  TestCollisionYwithGear(Gear: PGear; Dir: LongInt): boolean;
    43 
    43 
    44 function  TestCollisionXKick(Gear: PGear; Dir: LongInt): boolean;
    44 function  TestCollisionXKick(Gear: PGear; Dir: LongInt): boolean;
    45 function  TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean;
    45 function  TestCollisionYKick(Gear: PGear; Dir: LongInt): boolean;
       
    46 
       
    47 function  CountCollisionsX(Gear: PGear; Dir: LongInt): LongInt;
    46 
    48 
    47 function  TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
    49 function  TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
    48 function  TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
    50 function  TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
    49 
    51 
    50 function  TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
    52 function  TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
   299     TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir)
   301     TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir)
   300 else TestCollisionXwithXYShift:= TestCollisionX(Gear, Dir);
   302 else TestCollisionXwithXYShift:= TestCollisionX(Gear, Dir);
   301 Gear^.X:= Gear^.X - ShiftX;
   303 Gear^.X:= Gear^.X - ShiftX;
   302 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
   304 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
   303 end;
   305 end;
       
   306 
       
   307 function CountCollisionsX(Gear: PGear; Dir: LongInt): LongInt;
       
   308 var x, y, i, cnt: LongInt;
       
   309 begin
       
   310 cnt:= 0;
       
   311 x:= hwRound(Gear^.X);
       
   312 if Dir < 0 then x:= x - Gear^.Radius
       
   313            else x:= x + Gear^.Radius;
       
   314 if (x and LAND_WIDTH_MASK) = 0 then
       
   315    begin
       
   316    y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
       
   317    i:= y + Gear^.Radius * 2 - 2;
       
   318    repeat
       
   319      if (y and LAND_HEIGHT_MASK) = 0 then
       
   320         if Land[y, x] > 255 then inc(cnt);
       
   321      inc(y)
       
   322    until (y > i);
       
   323    end;
       
   324 CountCollisionsX:= cnt
       
   325 end;
       
   326 
   304 function TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
   327 function TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
   305 var x, y, i: LongInt;
   328 var x, y, i: LongInt;
   306 begin
   329 begin
   307 x:= hwRound(Gear^.X);
   330 x:= hwRound(Gear^.X);
   308 if Dir < 0 then x:= x - Gear^.Radius
   331 if Dir < 0 then x:= x - Gear^.Radius