hedgewars/uGearsHedgehog.pas
changeset 11484 cb64affd7715
parent 11468 2f6f8baa2a97
child 11510 64c1ea171204
equal deleted inserted replaced
11483:dbc0d54798dc 11484:cb64affd7715
   874 
   874 
   875 ////////////////////////////////////////////////////////////////////////////////
   875 ////////////////////////////////////////////////////////////////////////////////
   876 procedure doStepHedgehogMoving(Gear: PGear);
   876 procedure doStepHedgehogMoving(Gear: PGear);
   877 var isFalling, isUnderwater: boolean;
   877 var isFalling, isUnderwater: boolean;
   878     land: Word;
   878     land: Word;
       
   879     cnt: LongWord;
   879 begin
   880 begin
   880 if Gear^.Hedgehog^.Unplaced then
   881 if Gear^.Hedgehog^.Unplaced then
   881     begin
   882     begin
   882     Gear^.dY:= _0;
   883     Gear^.dY:= _0;
   883     Gear^.dX:= _0;
   884     Gear^.dX:= _0;
  1035                         if hwAbs(Gear^.dX) > _0_02 then
  1036                         if hwAbs(Gear^.dX) > _0_02 then
  1036                             Gear^.dX:= -Gear^.Elasticity * Gear^.dX
  1037                             Gear^.dX:= -Gear^.Elasticity * Gear^.dX
  1037                         else
  1038                         else
  1038                             begin
  1039                             begin
  1039                             Gear^.State:= Gear^.State and (not gstMoving);
  1040                             Gear^.State:= Gear^.State and (not gstMoving);
  1040                             while TestCollisionYWithGear(Gear,1) = 0 do
  1041                             cnt:= 0;
  1041                                 Gear^.Y:= Gear^.Y+_1;
  1042                             while (cnt < 6) and (not CheckGearDrowning(Gear)) and (Gear <> nil) and (TestCollisionYWithGear(Gear,1) = 0) do
       
  1043                                 begin
       
  1044                                 Gear^.Y:= Gear^.Y + _1;
       
  1045                                 inc(cnt)
       
  1046                                 end;
       
  1047 
  1042                             SetLittle(Gear^.dX)
  1048                             SetLittle(Gear^.dX)
  1043                             end
  1049                             end
  1044             else
  1050             else
  1045                 begin
  1051                 begin
  1046                 Gear^.State:= Gear^.State and (not gstMoving);
  1052                 Gear^.State:= Gear^.State and (not gstMoving);
  1047                 while TestCollisionYWithGear(Gear,1) = 0 do
  1053                 cnt:= 0;
  1048                     Gear^.Y:= Gear^.Y+_1;
  1054                 while (cnt < 6) and (not CheckGearDrowning(Gear)) and (Gear <> nil) and (TestCollisionYWithGear(Gear,1) = 0) do
       
  1055                     begin
       
  1056                     Gear^.Y:= Gear^.Y + _1;
       
  1057                     inc(cnt)
       
  1058                     end;
  1049                 SetLittle(Gear^.dX)
  1059                 SetLittle(Gear^.dX)
  1050                 end
  1060                 end
  1051         else if (hwAbs(Gear^.dX) > cLittle)
  1061         else if (hwAbs(Gear^.dX) > cLittle)
  1052         and ((Gear^.State and gstHHJumping) = 0) then
  1062         and ((Gear^.State and gstHHJumping) = 0) then
  1053             Gear^.dX:= -Gear^.Elasticity * Gear^.dX
  1063             Gear^.dX:= -Gear^.Elasticity * Gear^.dX
  1057 if (not isFalling)
  1067 if (not isFalling)
  1058   and (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
  1068   and (hwAbs(Gear^.dX) + hwAbs(Gear^.dY) < _0_03) then
  1059     begin
  1069     begin
  1060     Gear^.State:= Gear^.State and (not gstWinner);
  1070     Gear^.State:= Gear^.State and (not gstWinner);
  1061     Gear^.State:= Gear^.State and (not gstMoving);
  1071     Gear^.State:= Gear^.State and (not gstMoving);
  1062     while (not CheckGearDrowning(Gear)) and (Gear <> nil) and (TestCollisionYWithGear(Gear,1) = 0) do
  1072     cnt:= 0;
       
  1073     while (cnt < 6) and (not CheckGearDrowning(Gear)) and (Gear <> nil) and (TestCollisionYWithGear(Gear,1) = 0) do
       
  1074         begin
  1063         Gear^.Y:= Gear^.Y + _1;
  1075         Gear^.Y:= Gear^.Y + _1;
       
  1076         inc(cnt)
       
  1077         end;
  1064 
  1078 
  1065     // could become nil in CheckGearDrowning if ai's hog fails to respawn in ai survival
  1079     // could become nil in CheckGearDrowning if ai's hog fails to respawn in ai survival
  1066     if Gear = nil then exit;
  1080     if Gear = nil then exit;
  1067     SetLittle(Gear^.dX);
  1081     SetLittle(Gear^.dX);
  1068     Gear^.dY:= _0
  1082     Gear^.dY:= _0