hedgewars/uCollisions.pas
changeset 6081 537bbd5c1a62
parent 5919 f737843dd331
child 6123 0cb751caf0ac
equal deleted inserted replaced
6080:ce02ddfe8aa1 6081:537bbd5c1a62
    37 procedure DeleteCI(Gear: PGear);
    37 procedure DeleteCI(Gear: PGear);
    38 
    38 
    39 function  CheckGearsCollision(Gear: PGear): PGearArray;
    39 function  CheckGearsCollision(Gear: PGear): PGearArray;
    40 
    40 
    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): Word;
    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  TestCollisionX(Gear: PGear; Dir: LongInt): boolean;
   155    until (y > i);
   155    until (y > i);
   156    end;
   156    end;
   157 TestCollisionXwithGear:= false
   157 TestCollisionXwithGear:= false
   158 end;
   158 end;
   159 
   159 
   160 function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): boolean;
   160 function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): Word;
   161 var x, y, i: LongInt;
   161 var x, y, i: LongInt;
   162     TestWord: LongWord;
   162     TestWord: LongWord;
   163 begin
   163 begin
   164 if Gear^.IntersectGear <> nil then
   164 if Gear^.IntersectGear <> nil then
   165    with Gear^ do
   165    with Gear^ do
   179    begin
   179    begin
   180    x:= hwRound(Gear^.X) - Gear^.Radius + 1;
   180    x:= hwRound(Gear^.X) - Gear^.Radius + 1;
   181    i:= x + Gear^.Radius * 2 - 2;
   181    i:= x + Gear^.Radius * 2 - 2;
   182    repeat
   182    repeat
   183      if (x and LAND_WIDTH_MASK) = 0 then
   183      if (x and LAND_WIDTH_MASK) = 0 then
   184         if Land[y, x] > TestWord then exit(true);
   184         if Land[y, x] > TestWord then exit(Land[y, x]);
   185      inc(x)
   185      inc(x)
   186    until (x > i);
   186    until (x > i);
   187    end;
   187    end;
   188 TestCollisionYwithGear:= false
   188 TestCollisionYwithGear:= 0
   189 end;
   189 end;
   190 
   190 
   191 function TestCollisionXKick(Gear: PGear; Dir: LongInt): boolean;
   191 function TestCollisionXKick(Gear: PGear; Dir: LongInt): boolean;
   192 var x, y, mx, my, i: LongInt;
   192 var x, y, mx, my, i: LongInt;
   193     flag: boolean;
   193     flag: boolean;
   342 
   342 
   343 function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
   343 function TestCollisionYwithXYShift(Gear: PGear; ShiftX, ShiftY: LongInt; Dir: LongInt; withGear: boolean = true): boolean;
   344 begin
   344 begin
   345 Gear^.X:= Gear^.X + int2hwFloat(ShiftX);
   345 Gear^.X:= Gear^.X + int2hwFloat(ShiftX);
   346 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY);
   346 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY);
   347 if withGear then TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir)
   347 if withGear then TestCollisionYwithXYShift:= TestCollisionYwithGear(Gear, Dir) <> 0
   348 else TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir);
   348 else TestCollisionYwithXYShift:= TestCollisionY(Gear, Dir);
   349 Gear^.X:= Gear^.X - int2hwFloat(ShiftX);
   349 Gear^.X:= Gear^.X - int2hwFloat(ShiftX);
   350 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
   350 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
   351 end;
   351 end;
   352 
   352