hedgewars/HHHandlers.inc
changeset 74 42257fee61ae
parent 73 fe1c62875a19
child 75 d2b737858ff7
equal deleted inserted replaced
73:fe1c62875a19 74:42257fee61ae
   123 procedure doStepHedgehog(Gear: PGear); forward;
   123 procedure doStepHedgehog(Gear: PGear); forward;
   124 ////////////////////////////////////////////////////////////////////////////////
   124 ////////////////////////////////////////////////////////////////////////////////
   125 procedure doStepHedgehogDriven(Gear: PGear);
   125 procedure doStepHedgehogDriven(Gear: PGear);
   126 const StepTicks: LongWord = 0;
   126 const StepTicks: LongWord = 0;
   127 var t: PGear;
   127 var t: PGear;
       
   128     PrevdX: integer;
   128 begin
   129 begin
   129 if isInMultiShoot and (Gear.Damage = 0) then
   130 if isInMultiShoot and (Gear.Damage = 0) then
   130    begin
   131    begin
   131    exit
   132    exit
   132    end;
   133    end;
   245          Gear.X:= Gear.X - Sign(Gear.dX)*0.00008; // компенсация сдвига %)
   246          Gear.X:= Gear.X - Sign(Gear.dX)*0.00008; // компенсация сдвига %)
   246          Gear.State:= Gear.State or gstFalling or gstHHJumping;
   247          Gear.State:= Gear.State or gstFalling or gstHHJumping;
   247          exit
   248          exit
   248          end;
   249          end;
   249       end;
   250       end;
       
   251    PrevdX:= Sign(Gear.dX);
   250    if (Gear.Message and gm_Left  )<>0 then Gear.dX:= -1.0 else
   252    if (Gear.Message and gm_Left  )<>0 then Gear.dX:= -1.0 else
   251    if (Gear.Message and gm_Right )<>0 then Gear.dX:=  1.0 else exit;
   253    if (Gear.Message and gm_Right )<>0 then Gear.dX:=  1.0 else exit;
       
   254    StepTicks:= cHHStepTicks;
       
   255    if PrevdX <> Sign(Gear.dX) then exit;
   252    PHedgehog(Gear.Hedgehog).visStepPos:= (PHedgehog(Gear.Hedgehog).visStepPos + 1) and 7;
   256    PHedgehog(Gear.Hedgehog).visStepPos:= (PHedgehog(Gear.Hedgehog).visStepPos + 1) and 7;
   253    StepTicks:= cHHStepTicks;
       
   254    if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
   257    if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
   255       begin
   258       begin
   256       if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX))
   259       if not (TestCollisionXwithXYShift(Gear, 0, -6, Sign(Gear.dX))
   257          or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
   260          or TestCollisionYwithGear(Gear, -1)) then Gear.Y:= Gear.Y - 1;
   258       if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX))
   261       if not (TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX))
   306 ////////////////////////////////////////////////////////////////////////////////
   309 ////////////////////////////////////////////////////////////////////////////////
   307 procedure doStepHedgehogFree(Gear: PGear);
   310 procedure doStepHedgehogFree(Gear: PGear);
   308 begin
   311 begin
   309 //DeleteCI(Gear);
   312 //DeleteCI(Gear);
   310 if not TestCollisionYwithGear(Gear, 1) then
   313 if not TestCollisionYwithGear(Gear, 1) then
   311    if TestCollisionYwithXYShift(Gear, 0, 1, 1) then Gear.Y:= Gear.Y + 1 else
       
   312    begin
   314    begin
   313    if (Gear.dY < 0) and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0;
   315    if (Gear.dY < 0) and TestCollisionYwithGear(Gear, -1) then Gear.dY:= 0;
   314    Gear.State:= Gear.State or gstFalling or gstMoving;
   316    Gear.State:= Gear.State or gstFalling or gstMoving;
   315    Gear.dY:= Gear.dY + cGravity
   317    Gear.dY:= Gear.dY + cGravity
   316    end else begin
   318    end else begin
   317    CheckHHDamage(Gear);
   319    CheckHHDamage(Gear);
   318    if ((abs(Gear.dX) + abs(Gear.dY)) < 0.55)
   320    if ((abs(Gear.dX) + abs(Gear.dY)) < 0.55)
   319       and ((Gear.State and gstHHJumping) <> 0) then Gear.dX:= 0.0000001 * Sign(Gear.dX);
   321       and ((Gear.State and gstHHJumping) <> 0) then Gear.dX:= 0.0000001 * Sign(Gear.dX);
   320    Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
   322    Gear.State:= Gear.State and not (gstFalling or gstHHJumping);
   321    if Gear.dY > 0    then Gear.dY:= 0;
   323    if Gear.dY > 0 then Gear.dY:= 0;
   322    if ((Gear.State and gstMoving) <> 0) then Gear.dX:= Gear.dX * Gear.Friction
   324    if ((Gear.State and gstMoving) <> 0) then Gear.dX:= Gear.dX * Gear.Friction
   323    end;
   325    end;
   324 
   326 
   325 if (Gear.State <> 0) then DeleteCI(Gear);
   327 if (Gear.State <> 0) then DeleteCI(Gear);
   326 
   328 
   327 if (Gear.State and gstMoving) <> 0 then
   329 if (Gear.State and gstMoving) <> 0 then
   328    if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
   330    if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
   329       if ((Gear.State and gstFalling) = 0) then
   331       if ((Gear.State and gstFalling) = 0) then
   330          if abs(Gear.dX) > 0.01 then
   332          if abs(Gear.dX) > 0.01 then
   331             if not TestCollisionXwithXYShift(Gear, 0, -1, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.99; Gear.Y:= Gear.Y - 1 end else
   333             if not TestCollisionXwithXYShift(Gear, Sign(Gear.dX) - Gear.dX, -1, Sign(Gear.dX)) then begin Gear.X:= Gear.X + Gear.dX; Gear.dX:= Gear.dX * 0.96; Gear.Y:= Gear.Y - 1 end else
   332             if not TestCollisionXwithXYShift(Gear, 0, -2, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.98; Gear.Y:= Gear.Y - 2 end else
   334             if not TestCollisionXwithXYShift(Gear, Sign(Gear.dX) - Gear.dX, -2, Sign(Gear.dX)) then begin Gear.X:= Gear.X + Gear.dX; Gear.dX:= Gear.dX * 0.93; Gear.Y:= Gear.Y - 2 end else
   333             if not TestCollisionXwithXYShift(Gear, 0, -3, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.97; Gear.Y:= Gear.Y - 3 end else
   335             if not TestCollisionXwithXYShift(Gear, Sign(Gear.dX) - Gear.dX, -3, Sign(Gear.dX)) then begin Gear.X:= Gear.X + Gear.dX; Gear.dX:= Gear.dX * 0.90; Gear.Y:= Gear.Y - 3 end else
   334             if not TestCollisionXwithXYShift(Gear, 0, -4, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.96; Gear.Y:= Gear.Y - 4 end else
   336             if not TestCollisionXwithXYShift(Gear, Sign(Gear.dX) - Gear.dX, -4, Sign(Gear.dX)) then begin Gear.X:= Gear.X + Gear.dX; Gear.dX:= Gear.dX * 0.87; Gear.Y:= Gear.Y - 4 end else
   335             if not TestCollisionXwithXYShift(Gear, 0, -5, Sign(Gear.dX)) then begin Gear.dX:= Gear.dX * 0.95; Gear.Y:= Gear.Y - 5 end else
   337             if not TestCollisionXwithXYShift(Gear, Sign(Gear.dX) - Gear.dX, -5, Sign(Gear.dX)) then begin Gear.X:= Gear.X + Gear.dX; Gear.dX:= Gear.dX * 0.84; Gear.Y:= Gear.Y - 5 end else
   336             if abs(Gear.dX) > 0.02 then Gear.dX:= -0.3 * Gear.dX
   338             if abs(Gear.dX) > 0.02 then Gear.dX:= -0.5 * Gear.dX
   337                                    else begin
   339                                    else begin
   338                                         Gear.State:= Gear.State and not gstMoving;
   340                                         Gear.State:= Gear.State and not gstMoving;
   339                                         Gear.dX:= 0.0000001 * Sign(Gear.dX)
   341                                         Gear.dX:= 0.0000001 * Sign(Gear.dX)
   340                                         end
   342                                         end
   341                                    else begin
   343                                    else begin
   342                                         Gear.State:= Gear.State and not gstMoving;
   344                                         Gear.State:= Gear.State and not gstMoving;
   343                                         Gear.dX:= 0.0000001 * Sign(Gear.dX)
   345                                         Gear.dX:= 0.0000001 * Sign(Gear.dX)
   344                                         end
   346                                         end
   345          else Gear.dX:= -0.8 * Gear.dX;
   347          else Gear.dX:= -Gear.dX;
   346 
   348 
   347 if ((Gear.State and gstFalling) = 0)and
   349 if ((Gear.State and gstFalling) = 0)and
   348    (sqr(Gear.dX) + sqr(Gear.dY) < 0.0008) then
   350    (sqr(Gear.dX) + sqr(Gear.dY) < 0.0008) then
   349    begin
   351    begin
   350    Gear.State:= Gear.State and not gstMoving;
   352    Gear.State:= Gear.State and not gstMoving;
   353    end else Gear.State:= Gear.State or gstMoving;
   355    end else Gear.State:= Gear.State or gstMoving;
   354 
   356 
   355 if (Gear.State and gstMoving) <> 0 then
   357 if (Gear.State and gstMoving) <> 0 then
   356    begin
   358    begin
   357    Gear.X:= Gear.X + Gear.dX;
   359    Gear.X:= Gear.X + Gear.dX;
   358    Gear.Y:= Gear.Y + Gear.dY
   360    Gear.Y:= Gear.Y + Gear.dY;
       
   361    if (Gear.dY > 0) and not TestCollisionYwithGear(Gear, 1) and TestCollisionYwithXYShift(Gear, 0, 1, 1) then
       
   362       begin
       
   363       Gear.dY:= 0;
       
   364       Gear.Y:= Gear.Y + 1
       
   365       end;
   359    end else
   366    end else
   360    if Gear.Health = 0 then
   367    if Gear.Health = 0 then
   361       begin
   368       begin
   362       if AllInactive then
   369       if AllInactive then
   363          begin
   370          begin