hedgewars/uCollisions.pas
changeset 5834 f9944a75b350
parent 5830 ea4d1fe665d7
child 5896 9ce1cf4e5a32
equal deleted inserted replaced
5833:d0c742472d46 5834:f9944a75b350
    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;
       
    48 
    46 
    49 function  TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
    47 function  TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
    50 function  TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
    48 function  TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
    51 
    49 
    52 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;
   301     TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir)
   299     TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir)
   302 else TestCollisionXwithXYShift:= TestCollisionX(Gear, Dir);
   300 else TestCollisionXwithXYShift:= TestCollisionX(Gear, Dir);
   303 Gear^.X:= Gear^.X - ShiftX;
   301 Gear^.X:= Gear^.X - ShiftX;
   304 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
   302 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
   305 end;
   303 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 
       
   327 function TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
   304 function TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
   328 var x, y, i: LongInt;
   305 var x, y, i: LongInt;
   329 begin
   306 begin
   330 x:= hwRound(Gear^.X);
   307 x:= hwRound(Gear^.X);
   331 if Dir < 0 then x:= x - Gear^.Radius
   308 if Dir < 0 then x:= x - Gear^.Radius