hedgewars/uCollisions.pas
changeset 505 fcba7d7aea0d
parent 504 13b6ebc53627
child 511 2b5b9e00419d
equal deleted inserted replaced
504:13b6ebc53627 505:fcba7d7aea0d
   101 CheckGearsCollision:= Result
   101 CheckGearsCollision:= Result
   102 end;
   102 end;
   103 
   103 
   104 function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): boolean;
   104 function TestCollisionXwithGear(Gear: PGear; Dir: LongInt): boolean;
   105 var x, y, i: LongInt;
   105 var x, y, i: LongInt;
   106 begin
   106     TestWord: LongWord;
       
   107 begin
       
   108 if Gear^.IntersectGear <> nil then
       
   109    with Gear^ do
       
   110         if (hwRound(IntersectGear^.X) + IntersectGear^.Radius < hwRound(X) - Radius) or
       
   111            (hwRound(IntersectGear^.X) - IntersectGear^.Radius > hwRound(X) + Radius) then
       
   112            begin
       
   113            IntersectGear:= nil;
       
   114            TestWord:= 0
       
   115            end else    
       
   116            TestWord:= COLOR_LAND - 1
       
   117    else TestWord:= 0;
       
   118    
   107 x:= hwRound(Gear^.X);
   119 x:= hwRound(Gear^.X);
   108 if Dir < 0 then x:= x - Gear^.Radius
   120 if Dir < 0 then x:= x - Gear^.Radius
   109            else x:= x + Gear^.Radius;
   121            else x:= x + Gear^.Radius;
   110 if (x and $FFFFF800) = 0 then
   122 if (x and $FFFFF800) = 0 then
   111    begin
   123    begin
   112    y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
   124    y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
   113    i:= y + Gear^.Radius * 2 - 2;
   125    i:= y + Gear^.Radius * 2 - 2;
   114    repeat
   126    repeat
   115      if (y and $FFFFFC00) = 0 then
   127      if (y and $FFFFFC00) = 0 then
   116         if Land[y, x] <> 0 then exit(true);
   128         if Land[y, x] > TestWord then exit(true);
   117      inc(y)
   129      inc(y)
   118    until (y > i);
   130    until (y > i);
   119    end;
   131    end;
   120 TestCollisionXwithGear:= false
   132 TestCollisionXwithGear:= false
       
   133 end;
       
   134 
       
   135 function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): boolean;
       
   136 var x, y, i: LongInt;
       
   137     TestWord: LongWord;
       
   138 begin
       
   139 if Gear^.IntersectGear <> nil then
       
   140    with Gear^ do
       
   141         if (hwRound(IntersectGear^.Y) + IntersectGear^.Radius < hwRound(Y) - Radius) or
       
   142            (hwRound(IntersectGear^.Y) - IntersectGear^.Radius > hwRound(Y) + Radius) then
       
   143            begin
       
   144            IntersectGear:= nil;
       
   145            TestWord:= 0
       
   146            end else    
       
   147            TestWord:= COLOR_LAND - 1
       
   148    else TestWord:= 0;
       
   149 
       
   150 y:= hwRound(Gear^.Y);
       
   151 if Dir < 0 then y:= y - Gear^.Radius
       
   152            else y:= y + Gear^.Radius;
       
   153 if (y and $FFFFFC00) = 0 then
       
   154    begin
       
   155    x:= hwRound(Gear^.X) - Gear^.Radius + 1;
       
   156    i:= x + Gear^.Radius * 2 - 2;
       
   157    repeat
       
   158      if (x and $FFFFF800) = 0 then
       
   159         if Land[y, x] > TestWord then exit(true);
       
   160      inc(x)
       
   161    until (x > i);
       
   162    end;
       
   163 TestCollisionYwithGear:= false
   121 end;
   164 end;
   122 
   165 
   123 function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean;
   166 function TestCollisionXwithXYShift(Gear: PGear; ShiftX: hwFloat; ShiftY: LongInt; Dir: LongInt): boolean;
   124 begin
   167 begin
   125 Gear^.X:= Gear^.X + ShiftX;
   168 Gear^.X:= Gear^.X + ShiftX;
   126 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY);
   169 Gear^.Y:= Gear^.Y + int2hwFloat(ShiftY);
   127 TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir);
   170 TestCollisionXwithXYShift:= TestCollisionXwithGear(Gear, Dir);
   128 Gear^.X:= Gear^.X - ShiftX;
   171 Gear^.X:= Gear^.X - ShiftX;
   129 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
   172 Gear^.Y:= Gear^.Y - int2hwFloat(ShiftY)
   130 end;
       
   131 
       
   132 function TestCollisionYwithGear(Gear: PGear; Dir: LongInt): boolean;
       
   133 var x, y, i: LongInt;
       
   134 begin
       
   135 y:= hwRound(Gear^.Y);
       
   136 if Dir < 0 then y:= y - Gear^.Radius
       
   137            else y:= y + Gear^.Radius;
       
   138 if (y and $FFFFFC00) = 0 then
       
   139    begin
       
   140    x:= hwRound(Gear^.X) - Gear^.Radius + 1;
       
   141    i:= x + Gear^.Radius * 2 - 2;
       
   142    repeat
       
   143      if (x and $FFFFF800) = 0 then
       
   144         if Land[y, x] <> 0 then exit(true);
       
   145      inc(x)
       
   146    until (x > i);
       
   147    end;
       
   148 TestCollisionYwithGear:= false
       
   149 end;
   173 end;
   150 
   174 
   151 function TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
   175 function TestCollisionY(Gear: PGear; Dir: LongInt): boolean;
   152 var x, y, i: LongInt;
   176 var x, y, i: LongInt;
   153 begin
   177 begin