hedgewars/uCollisions.pas
changeset 4798 84fb1ff0a1c0
parent 4705 593ef1ad3cd3
child 4976 088d40d8aba2
equal deleted inserted replaced
4797:15a443eec371 4798:84fb1ff0a1c0
    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 
    46 
       
    47 function  TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
    47 function  TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
    48 function  TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
    48 
    49 
    49 function  TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean;
    50 function  TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean;
    50 function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean;
    51 function  TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt): boolean;
    51 
    52 
   287 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY);
   288 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY);
   288 TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir);
   289 TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir);
   289 Gear^.X:= Gear^.X - ShiftX;
   290 Gear^.X:= Gear^.X - ShiftX;
   290 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
   291 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
   291 end;
   292 end;
       
   293 function TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
       
   294 var x, y, i: LongInt;
       
   295 begin
       
   296 x:= hwRound(Gear^.X);
       
   297 if Dir < 0 then x:= x - Gear^.Radius
       
   298            else x:= x + Gear^.Radius;
       
   299 if (x and LAND_WIDTH_MASK) = 0 then
       
   300    begin
       
   301    y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
       
   302    i:= y + Gear^.Radius * 2 - 2;
       
   303    repeat
       
   304      if (y and LAND_HEIGHT_MASK) = 0 then
       
   305         if Land[y, x] > 255 then exit(true);
       
   306      inc(y)
       
   307    until (y > i);
       
   308    end;
       
   309 TestCollisionX:= false
       
   310 end;
   292 
   311 
   293 function TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
   312 function TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
   294 var x, y, i: LongInt;
   313 var x, y, i: LongInt;
   295 begin
   314 begin
   296 y:= hwRound(Gear^.Y);
   315 y:= hwRound(Gear^.Y);