hedgewars/GSHandlers.inc
changeset 542 ec26095f1bed
parent 540 b06c5aace2fa
child 543 465e2ec8f05f
equal deleted inserted replaced
541:bc7be7f6d3e8 542:ec26095f1bed
    68 if hwRound(Gear^.Y) > Gear^.Radius + cWaterLine + cVisibleWater then DeleteGear(Gear)
    68 if hwRound(Gear^.Y) > Gear^.Radius + cWaterLine + cVisibleWater then DeleteGear(Gear)
    69 end;
    69 end;
    70 
    70 
    71 ////////////////////////////////////////////////////////////////////////////////
    71 ////////////////////////////////////////////////////////////////////////////////
    72 procedure doStepFallingGear(Gear: PGear);
    72 procedure doStepFallingGear(Gear: PGear);
       
    73 var isFalling: boolean;
    73 begin
    74 begin
    74 Gear^.State:= Gear^.State and not gstCollision;
    75 Gear^.State:= Gear^.State and not gstCollision;
    75 
    76 
    76 if Gear^.dY.isNegative then
    77 if Gear^.dY.isNegative then
    77    begin
    78    begin
    78    Gear^.State:= Gear^.State or gstFalling;
    79    isFalling:= true;
    79    if TestCollisionYwithGear(Gear, -1) then
    80    if TestCollisionYwithGear(Gear, -1) then
    80       begin
    81       begin
    81       Gear^.dX:=   Gear^.dX * Gear^.Friction;
    82       Gear^.dX:=   Gear^.dX * Gear^.Friction;
    82       Gear^.dY:= - Gear^.dY * Gear^.Elasticity;
    83       Gear^.dY:= - Gear^.dY * Gear^.Elasticity;
    83       Gear^.State:= Gear^.State or gstCollision
    84       Gear^.State:= Gear^.State or gstCollision
    84       end
    85       end
    85    end else
    86    end else
    86    if TestCollisionYwithGear(Gear, 1) then
    87    if TestCollisionYwithGear(Gear, 1) then
    87       begin
    88       begin
    88       Gear^.State:= Gear^.State and not gstFalling;
    89       isFalling:= false;
    89       Gear^.dX:=   Gear^.dX * Gear^.Friction;
    90       Gear^.dX:=   Gear^.dX * Gear^.Friction;
    90       Gear^.dY:= - Gear^.dY * Gear^.Elasticity;
    91       Gear^.dY:= - Gear^.dY * Gear^.Elasticity;
    91       Gear^.State:= Gear^.State or gstCollision
    92       Gear^.State:= Gear^.State or gstCollision
    92       end else Gear^.State:= Gear^.State or gstFalling;
    93       end else isFalling:= true;
    93 
    94 
    94 if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
    95 if TestCollisionXwithGear(Gear, hwSign(Gear^.dX)) then
    95    begin
    96    begin
    96    Gear^.dX:= - Gear^.dX * Gear^.Elasticity;
    97    Gear^.dX:= - Gear^.dX * Gear^.Elasticity;
    97    Gear^.State:= Gear^.State or gstCollision
    98    Gear^.State:= Gear^.State or gstCollision
    98    end;
    99    end;
    99 
   100 
   100 if (Gear^.State and gstFalling) <> 0 then Gear^.dY:= Gear^.dY + cGravity;
   101 if isFalling then Gear^.dY:= Gear^.dY + cGravity;
   101 
   102 
   102 Gear^.X:= Gear^.X + Gear^.dX;
   103 Gear^.X:= Gear^.X + Gear^.dX;
   103 Gear^.Y:= Gear^.Y + Gear^.dY;
   104 Gear^.Y:= Gear^.Y + Gear^.dY;
   104 CheckGearDrowning(Gear);
   105 CheckGearDrowning(Gear);
   105 if (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) < _0_0002) and
   106 if (hwSqr(Gear^.dX) + hwSqr(Gear^.dY) < _0_0002) and
   106    ((Gear^.State and gstFalling) = 0) then Gear^.State:= Gear^.State and not gstMoving
   107    (not isFalling) then Gear^.State:= Gear^.State and not gstMoving
   107                                       else Gear^.State:= Gear^.State or      gstMoving
   108                    else Gear^.State:= Gear^.State or      gstMoving
   108 end;
   109 end;
   109 
   110 
   110 ////////////////////////////////////////////////////////////////////////////////
   111 ////////////////////////////////////////////////////////////////////////////////
   111 procedure doStepCloud(Gear: PGear);
   112 procedure doStepCloud(Gear: PGear);
   112 begin
   113 begin
   503       HHGear^.State:= HHGear^.State or gstNoDamage;
   504       HHGear^.State:= HHGear^.State or gstNoDamage;
   504       AmmoShove(Gear, 2, 14);
   505       AmmoShove(Gear, 2, 14);
   505       HHGear^.State:= HHGear^.State and not gstNoDamage
   506       HHGear^.State:= HHGear^.State and not gstNoDamage
   506       end;
   507       end;
   507 
   508 
   508    if (HHGear^.State and gstFalling) <> 0 then Gear^.Timer:= 0
   509    if (HHGear^.State and gstMoving) <> 0 then Gear^.Timer:= 0
   509    end;
   510    end;
   510 
   511 
   511 if b then
   512 if b then
   512    DrawTunnel(HHGear^.X - Gear^.dX * cHHRadius, HHGear^.Y - _4 - Gear^.dY * cHHRadius + hwAbs(Gear^.dY) * 7,
   513    DrawTunnel(HHGear^.X - Gear^.dX * cHHRadius, HHGear^.Y - _4 - Gear^.dY * cHHRadius + hwAbs(Gear^.dY) * 7,
   513               Gear^.dX, Gear^.dY,
   514               Gear^.dX, Gear^.dY,
   542     procedure DeleteMe;
   543     procedure DeleteMe;
   543     begin
   544     begin
   544       with HHGear^ do
   545       with HHGear^ do
   545            begin
   546            begin
   546            Message:= Message and not gm_Attack;
   547            Message:= Message and not gm_Attack;
   547            State:= State or gstFalling;
   548            State:= State or gstMoving;
   548            end;
   549            end;
   549       DeleteGear(Gear);
   550       DeleteGear(Gear);
   550       OnUsedAmmo(PHedgehog(HHGear^.Hedgehog)^);
   551       OnUsedAmmo(PHedgehog(HHGear^.Hedgehog)^);
   551       ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^)
   552       ApplyAmmoChanges(PHedgehog(HHGear^.Hedgehog)^)
   552     end;
   553     end;
   662 Gear^.X:= Gear^.X - Gear^.dX;
   663 Gear^.X:= Gear^.X - Gear^.dX;
   663 Gear^.Y:= Gear^.Y - Gear^.dY;
   664 Gear^.Y:= Gear^.Y - Gear^.dY;
   664 Gear^.Elasticity:= Gear^.Elasticity + _1;
   665 Gear^.Elasticity:= Gear^.Elasticity + _1;
   665 HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
   666 HHGear:= PHedgehog(Gear^.Hedgehog)^.Gear;
   666 DeleteCI(HHGear);
   667 DeleteCI(HHGear);
   667 if (HHGear^.State and gstFalling) <> 0 then
   668 if (HHGear^.State and gstMoving) <> 0 then
   668    if TestCollisionYwithGear(HHGear, 1) then
   669    if TestCollisionYwithGear(HHGear, 1) then
   669       begin
   670       begin
   670       HHGear^.dY:= _0;
   671       HHGear^.dY:= _0;
   671       CheckHHDamage(HHGear);
   672       CheckHHDamage(HHGear);
   672       HHGear^.State:= HHGear^.State and not (gstFalling or gstHHJumping);
   673       HHGear^.State:= HHGear^.State and not (gstMoving or gstHHJumping);
   673       end else
   674       end else
   674       begin
   675       begin
   675       if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then SetLittle(HHGear^.dX);
   676       if TestCollisionXwithGear(HHGear, hwSign(HHGear^.dX)) then SetLittle(HHGear^.dX);
   676       HHGear^.X:= HHGear^.X + HHGear^.dX;
   677       HHGear^.X:= HHGear^.X + HHGear^.dX;
   677       HHGear^.Y:= HHGear^.Y + HHGear^.dY;
   678       HHGear^.Y:= HHGear^.Y + HHGear^.dY;
   752 end;
   753 end;
   753 
   754 
   754 ////////////////////////////////////////////////////////////////////////////////
   755 ////////////////////////////////////////////////////////////////////////////////
   755 procedure doStepMine(Gear: PGear);
   756 procedure doStepMine(Gear: PGear);
   756 begin
   757 begin
   757 if (Gear^.State and (gstMoving or gstFalling)) <> 0 then
   758 if (Gear^.State and gstMoving) <> 0 then
   758    begin
   759    begin
   759    DeleteCI(Gear);
   760    DeleteCI(Gear);
   760    doStepFallingGear(Gear);
   761    doStepFallingGear(Gear);
   761    if (Gear^.State and (gstMoving or gstFalling)) = 0 then
   762    if (Gear^.State and gstMoving) = 0 then
   762       begin
   763       begin
   763       AddGearCI(Gear);
   764       AddGearCI(Gear);
   764       Gear^.dX:= _0;
   765       Gear^.dX:= _0;
   765       Gear^.dY:= _0
   766       Gear^.dY:= _0
   766       end;
   767       end;
   975    end;
   976    end;
   976 
   977 
   977 HHGear^.dY:= HHGear^.dY + cGravity;
   978 HHGear^.dY:= HHGear^.dY + cGravity;
   978 if not (HHGear^.dY.isNegative) then
   979 if not (HHGear^.dY.isNegative) then
   979    begin
   980    begin
   980    HHGear^.State:= HHGear^.State or gstFalling;
   981    HHGear^.State:= HHGear^.State or gstMoving;
   981    DeleteGear(Gear);
   982    DeleteGear(Gear);
   982    AfterAttack;
   983    AfterAttack;
   983    exit
   984    exit
   984    end;
   985    end;
   985 HHGear^.Y:= HHGear^.Y + HHGear^.dY
   986 HHGear^.Y:= HHGear^.Y + HHGear^.dY
  1021         begin
  1022         begin
  1022         Message:= 0;
  1023         Message:= 0;
  1023         SetLittle(dx);
  1024         SetLittle(dx);
  1024         dY:= _0;
  1025         dY:= _0;
  1025         State:= State and not (gstAttacking or gstAttacked);
  1026         State:= State and not (gstAttacking or gstAttacked);
  1026         State:= State or gstFalling;
  1027         State:= State or gstMoving;
  1027         end;
  1028         end;
  1028    DeleteGear(Gear);
  1029    DeleteGear(Gear);
  1029    if Gear^.Timer > 10 then
  1030    if Gear^.Timer > 10 then
  1030       begin
  1031       begin
  1031       OnUsedAmmo(PHedgehog(HHGear^.Hedgehog)^);
  1032       OnUsedAmmo(PHedgehog(HHGear^.Hedgehog)^);
  1156    else begin
  1157    else begin
  1157         DeleteCI(HHGear);
  1158         DeleteCI(HHGear);
  1158         Gear^.doStep:= @doStepTeleportAfter;
  1159         Gear^.doStep:= @doStepTeleportAfter;
  1159         HHGear^.X:= int2hwFloat(TargetPoint.X);
  1160         HHGear^.X:= int2hwFloat(TargetPoint.X);
  1160         HHGear^.Y:= int2hwFloat(TargetPoint.Y);
  1161         HHGear^.Y:= int2hwFloat(TargetPoint.Y);
  1161         HHGear^.State:= HHGear^.State or gstFalling
  1162         HHGear^.State:= HHGear^.State or gstMoving
  1162         end;
  1163         end;
  1163 TargetPoint.X:= NoPointX
  1164 TargetPoint.X:= NoPointX
  1164 end;
  1165 end;
  1165 
  1166 
  1166 ////////////////////////////////////////////////////////////////////////////////
  1167 ////////////////////////////////////////////////////////////////////////////////