hedgewars/uCollisions.pas
changeset 536 33538aadb4e7
parent 521 bc8fd78d7598
child 538 74219eadab5e
equal deleted inserted replaced
535:a14eaf35cf4b 536:33538aadb4e7
   183    y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
   183    y:= hwRound(Gear^.Y) - Gear^.Radius + 1;
   184    i:= y + Gear^.Radius * 2 - 2;
   184    i:= y + Gear^.Radius * 2 - 2;
   185    repeat
   185    repeat
   186      if (y and $FFFFFC00) = 0 then
   186      if (y and $FFFFFC00) = 0 then
   187            if Land[y, x] = COLOR_LAND then exit(true)
   187            if Land[y, x] = COLOR_LAND then exit(true)
   188                                       else flag:= true;
   188            else if Land[y, x] <> 0 then flag:= true;
   189      inc(y)
   189      inc(y)
   190    until (y > i);
   190    until (y > i);
   191    end;
   191    end;
   192 TestCollisionXKick:= false;
   192 TestCollisionXKick:= false;
   193 
   193 
   194 if flag and (hwAbs(Gear^.dX) > cHHKick) then
   194 if flag then
   195    begin
   195    begin
       
   196    if hwAbs(Gear^.dX) < cHHKick then exit(true);
   196    if Count = 0 then exit;
   197    if Count = 0 then exit;
   197    mx:= hwRound(Gear^.X);
   198    mx:= hwRound(Gear^.X);
   198    my:= hwRound(Gear^.Y);
   199    my:= hwRound(Gear^.Y);
   199 
   200 
   200    for i:= 0 to Pred(Count) do
   201    for i:= 0 to Pred(Count) do
   202       if (Gear <> cGear) and
   203       if (Gear <> cGear) and
   203          (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius)) and
   204          (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius)) and
   204          ((mx > x) xor (Dir > 0)) then
   205          ((mx > x) xor (Dir > 0)) then
   205          if (cGear^.Kind in [gtHedgehog, gtMine]) then
   206          if (cGear^.Kind in [gtHedgehog, gtMine]) then
   206              begin
   207              begin
   207              Gear^.dX:= Gear^.dX {* _0_6};
       
   208              Gear^.dY:= Gear^.dY {* _0_6};
       
   209              with cGear^ do
   208              with cGear^ do
   210                   begin
   209                   begin
   211                   dX:= Gear^.dX {* _1_5};
   210                   dX:= Gear^.dX;
   212                   dY:= Gear^.dY {* _1_5};
   211                   dY:= Gear^.dY;
   213                   State:= State or gstMoving;
   212                   State:= State or gstMoving;
   214                   Active:= true
   213                   Active:= true
   215                   end;
   214                   end;
   216              DeleteCI(cGear);
   215              DeleteCI(cGear);
   217              exit
   216              exit
   233    i:= x + Gear^.Radius * 2 - 2;
   232    i:= x + Gear^.Radius * 2 - 2;
   234    repeat
   233    repeat
   235      if (x and $FFFFF800) = 0 then
   234      if (x and $FFFFF800) = 0 then
   236         if Land[y, x] > 0 then
   235         if Land[y, x] > 0 then
   237            if Land[y, x] = COLOR_LAND then exit(true)
   236            if Land[y, x] = COLOR_LAND then exit(true)
   238                                       else flag:= true;
   237            else if Land[y, x] <> 0 then flag:= true;
   239      inc(x)
   238      inc(x)
   240    until (x > i);
   239    until (x > i);
   241    end;
   240    end;
   242 TestCollisionYKick:= false;
   241 TestCollisionYKick:= false;
   243 
   242 
   244 if flag and (hwAbs(Gear^.dX) > cHHKick) then
   243 if flag then
   245    begin
   244    begin
       
   245    if hwAbs(Gear^.dX) < cHHKick then exit(true);
   246    if Count = 0 then exit;
   246    if Count = 0 then exit;
   247    mx:= hwRound(Gear^.X);
   247    mx:= hwRound(Gear^.X);
   248    my:= hwRound(Gear^.Y);
   248    my:= hwRound(Gear^.Y);
   249 
   249 
   250    for i:= 0 to Pred(Count) do
   250    for i:= 0 to Pred(Count) do
   252       if (Gear <> cGear) and
   252       if (Gear <> cGear) and
   253          (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius)) and
   253          (sqr(mx - x) + sqr(my - y) <= sqr(Radius + Gear^.Radius)) and
   254          ((my > y) xor (Dir > 0)) then
   254          ((my > y) xor (Dir > 0)) then
   255          if (cGear^.Kind in [gtHedgehog, gtMine]) then
   255          if (cGear^.Kind in [gtHedgehog, gtMine]) then
   256              begin
   256              begin
   257              Gear^.dX:= Gear^.dX {* _0_6};
       
   258              Gear^.dY:= Gear^.dY {* _0_6};
       
   259              with cGear^ do
   257              with cGear^ do
   260                   begin
   258                   begin
   261                   dX:= Gear^.dX {* _1_5};
   259                   dX:= Gear^.dX;
   262                   dY:= Gear^.dY {* _1_5};
   260                   dY:= Gear^.dY;
   263                   State:= State or gstMoving;
   261                   State:= State or gstMoving;
   264                   Active:= true
   262                   Active:= true
   265                   end;
   263                   end;
   266              DeleteCI(cGear);
   264              DeleteCI(cGear);
   267              exit
   265              exit