hedgewars/GSHandlers.inc
changeset 108 08f1fe6f21f8
parent 107 b08ce0293a51
child 109 ab0340f580c2
equal deleted inserted replaced
107:b08ce0293a51 108:08f1fe6f21f8
    44    end
    44    end
    45 end;
    45 end;
    46 
    46 
    47 procedure CheckCollision(Gear: PGear);
    47 procedure CheckCollision(Gear: PGear);
    48 begin
    48 begin
    49 if TestCollisionXwithGear(Gear, Sign(Gear.X)) or TestCollisionYwithGear(Gear, Sign(Gear.Y))
    49 if TestCollisionXwithGear(Gear, hwSign(Gear.X)) or TestCollisionYwithGear(Gear, hwSign(Gear.Y))
    50    then Gear.State:= Gear.State or      gstCollision
    50    then Gear.State:= Gear.State or      gstCollision
    51    else Gear.State:= Gear.State and not gstCollision
    51    else Gear.State:= Gear.State and not gstCollision
    52 end;
    52 end;
    53 
    53 
    54 procedure CheckHHDamage(Gear: PGear);
    54 procedure CheckHHDamage(Gear: PGear);
    78 
    78 
    79 ////////////////////////////////////////////////////////////////////////////////
    79 ////////////////////////////////////////////////////////////////////////////////
    80 procedure doStepFallingGear(Gear: PGear);
    80 procedure doStepFallingGear(Gear: PGear);
    81 var b: boolean;
    81 var b: boolean;
    82 begin
    82 begin
    83 if TestCollisionYwithGear(Gear, Sign(Gear.dY)) then
    83 if TestCollisionYwithGear(Gear, hwSign(Gear.dY)) then
    84    begin
    84    begin
    85    Gear.dX:=   Gear.dX * Gear.Friction;
    85    Gear.dX:=   Gear.dX * Gear.Friction;
    86    Gear.dY:= - Gear.dY * Gear.Elasticity;
    86    Gear.dY:= - Gear.dY * Gear.Elasticity;
    87    b:= false
    87    b:= false
    88    end else b:= true;
    88    end else b:= true;
    89 if TestCollisionXwithGear(Gear, Sign(Gear.dX)) then
    89 if TestCollisionXwithGear(Gear, hwSign(Gear.dX)) then
    90    begin
    90    begin
    91    Gear.dX:= - Gear.dX * Gear.Elasticity;
    91    Gear.dX:= - Gear.dX * Gear.Elasticity;
    92 //   Gear.dY:=   Gear.dY;
    92 //   Gear.dY:=   Gear.dY;
    93    b:= false
    93    b:= false
    94    end;
    94    end;
   382    SetAllHHToActive;
   382    SetAllHHToActive;
   383    end;
   383    end;
   384 if TestCollisionYwithGear(Gear, 1) then
   384 if TestCollisionYwithGear(Gear, 1) then
   385    begin
   385    begin
   386    Gear.dY:= 0;
   386    Gear.dY:= 0;
   387    HHGear.dX:= 0.0000001 * Sign(PGear(Gear.Hedgehog).dX);
   387    HHGear.dX:= 0.0000001 * hwSign(PGear(Gear.Hedgehog).dX);
   388    HHGear.dY:= 0;
   388    HHGear.dY:= 0;
   389    end else
   389    end else
   390    begin
   390    begin
   391    Gear.dY:= Gear.dY + cGravity;
   391    Gear.dY:= Gear.dY + cGravity;
   392    Gear.Y:= Gear.Y + Gear.dY;
   392    Gear.Y:= Gear.Y + Gear.dY;
   427 ////////////////////////////////////////////////////////////////////////////////
   427 ////////////////////////////////////////////////////////////////////////////////
   428 procedure doStepRopeWork(Gear: PGear);
   428 procedure doStepRopeWork(Gear: PGear);
   429 const flCheck: boolean = false;
   429 const flCheck: boolean = false;
   430 var HHGear: PGear;
   430 var HHGear: PGear;
   431     len, cs, cc, tx, ty: Double;
   431     len, cs, cc, tx, ty: Double;
   432     lx, ly: integer;
   432     lx, ly: LongInt;
   433 
   433 
   434     procedure DeleteMe;
   434     procedure DeleteMe;
   435     begin
   435     begin
   436       with HHGear^ do
   436       with HHGear^ do
   437            begin
   437            begin
   443       ApplyAmmoChanges(PHedgehog(Gear.Hedgehog)^)
   443       ApplyAmmoChanges(PHedgehog(Gear.Hedgehog)^)
   444     end;
   444     end;
   445 
   445 
   446 begin
   446 begin
   447 HHGear:= PHedgehog(Gear.Hedgehog).Gear;
   447 HHGear:= PHedgehog(Gear.Hedgehog).Gear;
       
   448 
   448 if ((HHGear.State and gstHHDriven) = 0)
   449 if ((HHGear.State and gstHHDriven) = 0)
   449    or (CheckGearDrowning(HHGear)) then
   450    or (CheckGearDrowning(HHGear)) then
   450    begin
   451    begin
   451    DeleteMe;
   452    DeleteMe;
   452    exit
   453    exit
   457 if (Gear.Message and gm_Left  <> 0) then HHGear.dX:= HHGear.dX - 0.0002 else
   458 if (Gear.Message and gm_Left  <> 0) then HHGear.dX:= HHGear.dX - 0.0002 else
   458 if (Gear.Message and gm_Right <> 0) then HHGear.dX:= HHGear.dX + 0.0002;
   459 if (Gear.Message and gm_Right <> 0) then HHGear.dX:= HHGear.dX + 0.0002;
   459 
   460 
   460 if not TestCollisionYwithGear(HHGear, 1) then HHGear.dY:= HHGear.dY + cGravity;
   461 if not TestCollisionYwithGear(HHGear, 1) then HHGear.dY:= HHGear.dY + cGravity;
   461 
   462 
   462 HHGear.DirAngle:= arctan2(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX);
   463 cs:= Gear.dY + HHGear.dY;
   463 cs:= sin(HHGear.DirAngle);
   464 cc:= Gear.dX + HHGear.dX;
   464 cc:= cos(HHGear.DirAngle);
   465 len:= 1 / sqrt(sqr(cc)+sqr(cs));
       
   466 cc:= cc * len;
       
   467 cs:= cs * len;
   465 
   468 
   466 flCheck:= not flCheck;
   469 flCheck:= not flCheck;
   467 if flCheck then  // check whether rope needs dividing
   470 if flCheck then  // check whether rope needs dividing
   468    begin
   471    begin
   469    len:= Gear.Elasticity - 20;
   472    len:= Gear.Elasticity - 20;
   470    while len > 5 do
   473    while len > 5 do
   471          begin
   474          begin
   472          tx:= cc*len;
   475          tx:= cc*len;
   473          ty:= cs*len;
   476          ty:= cs*len;
   474          lx:= round(Gear.X + tx) + Sign(HHGear.dX);
   477          lx:= round(Gear.X + tx) + hwSign(HHGear.dX);
   475          ly:= round(Gear.Y + ty) + Sign(HHGear.dY);
   478          ly:= round(Gear.Y + ty) + hwSign(HHGear.dY);
   476          if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0)and (Land[ly, lx] <> 0) then
   479          if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0)and (Land[ly, lx] <> 0) then
   477            begin
   480            begin
   478            with RopePoints.ar[RopePoints.Count] do
   481            with RopePoints.ar[RopePoints.Count] do
   479                 begin
   482                 begin
   480                 X:= Gear.X;
   483                 X:= Gear.X;
   507          end
   510          end
   508       end;
   511       end;
   509 
   512 
   510 Gear.dX:= HHGear.X - Gear.X;
   513 Gear.dX:= HHGear.X - Gear.X;
   511 Gear.dY:= HHGear.Y - Gear.Y;
   514 Gear.dY:= HHGear.Y - Gear.Y;
   512 HHGear.DirAngle:= arctan2(Gear.dY + HHGear.dY, Gear.dX + HHGear.dX);
   515 
   513 cs:= sin(HHGear.DirAngle);
   516 cs:= Gear.dY + HHGear.dY;
   514 cc:= cos(HHGear.DirAngle);
   517 cc:= Gear.dX + HHGear.dX;
       
   518 len:= 1 / sqrt(sqr(cc)+sqr(cs));
       
   519 cc:= cc * len;
       
   520 cs:= cs * len;
   515 
   521 
   516 HHGear.dX:= HHGear.X;
   522 HHGear.dX:= HHGear.X;
   517 HHGear.dY:= HHGear.Y;
   523 HHGear.dY:= HHGear.Y;
   518 
   524 
   519 if ((Gear.Message and gm_Down) <> 0) and (Gear.Elasticity < Gear.Friction) then
   525 if ((Gear.Message and gm_Down) <> 0) and (Gear.Elasticity < Gear.Friction) then
   520    if not (TestCollisionXwithGear(HHGear, Sign(Gear.dX))
   526    if not (TestCollisionXwithGear(HHGear, hwSign(Gear.dX))
   521         or TestCollisionYwithGear(HHGear, Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity + 0.3;
   527         or TestCollisionYwithGear(HHGear, hwSign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity + 0.3;
   522 
   528 
   523 if ((Gear.Message and gm_Up) <> 0) and (Gear.Elasticity > 30) then
   529 if ((Gear.Message and gm_Up) <> 0) and (Gear.Elasticity > 30) then
   524    if not (TestCollisionXwithGear(HHGear, -Sign(Gear.dX))
   530    if not (TestCollisionXwithGear(HHGear, -hwSign(Gear.dX))
   525         or TestCollisionYwithGear(HHGear, -Sign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity - 0.3;
   531         or TestCollisionYwithGear(HHGear, -hwSign(Gear.dY))) then Gear.Elasticity:= Gear.Elasticity - 0.3;
   526 
   532 
   527 HHGear.X:= Gear.X + cc*Gear.Elasticity;
   533 HHGear.X:= Gear.X + cc*Gear.Elasticity;
   528 HHGear.Y:= Gear.Y + cs*Gear.Elasticity;
   534 HHGear.Y:= Gear.Y + cs*Gear.Elasticity;
   529 
   535 
       
   536 if (GameTicks >= 165118) and (GameTicks <= 165121) then
       
   537    begin
       
   538    AddFileLog('==9==> ('+floattostr(cc)+','+floattostr(cs)+')');
       
   539    AddFileLog('==a==>  '+floattostr(Gear.Elasticity));
       
   540    AddFileLog('==b==> ('+floattostr(HHGear.X)+','+floattostr(HHGear.Y)+')');
       
   541    end;
       
   542 
   530 HHGear.dX:= HHGear.X - HHGear.dX;
   543 HHGear.dX:= HHGear.X - HHGear.dX;
   531 HHGear.dY:= HHGear.Y - HHGear.dY;
   544 HHGear.dY:= HHGear.Y - HHGear.dY;
   532 
   545 
   533 if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then
   546 if TestCollisionXwithGear(HHGear, hwSign(HHGear.dX)) then
   534    HHGear.dX:= -0.6 * HHGear.dX;
   547    HHGear.dX:= -0.6 * HHGear.dX;
   535 if TestCollisionYwithGear(HHGear, Sign(HHGear.dY)) then
   548 if TestCollisionYwithGear(HHGear, hwSign(HHGear.dY)) then
   536    HHGear.dY:= -0.6 * HHGear.dY;
   549    HHGear.dY:= -0.6 * HHGear.dY;
   537 
   550 
   538 if (Gear.Message and gm_Attack) <> 0 then
   551 if (Gear.Message and gm_Attack) <> 0 then
   539    if (Gear.State and gsttmpFlag) <> 0 then DeleteMe else
   552    if (Gear.State and gsttmpFlag) <> 0 then DeleteMe else
   540 else if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag;
   553 else if (Gear.State and gsttmpFlag) = 0 then Gear.State:= Gear.State or gsttmpFlag;
   555       HHGear.dY:= 0;
   568       HHGear.dY:= 0;
   556       CheckHHDamage(HHGear);
   569       CheckHHDamage(HHGear);
   557       HHGear.State:= HHGear.State and not (gstFalling or gstHHJumping);
   570       HHGear.State:= HHGear.State and not (gstFalling or gstHHJumping);
   558       end else
   571       end else
   559       begin
   572       begin
   560       if TestCollisionXwithGear(HHGear, Sign(HHGear.dX)) then HHGear.dX:= 0.0000001 * Sign(HHGear.dX);
   573       if TestCollisionXwithGear(HHGear, hwSign(HHGear.dX)) then HHGear.dX:= 0.0000001 * hwSign(HHGear.dX);
   561       HHGear.X:= HHGear.X + HHGear.dX;
   574       HHGear.X:= HHGear.X + HHGear.dX;
   562       HHGear.Y:= HHGear.Y + HHGear.dY;
   575       HHGear.Y:= HHGear.Y + HHGear.dY;
   563       Gear.X:= Gear.X + HHGear.dX;
   576       Gear.X:= Gear.X + HHGear.dX;
   564       Gear.Y:= Gear.Y + HHGear.dY;
   577       Gear.Y:= Gear.Y + HHGear.dY;
   565       HHGear.dY:= HHGear.dY + cGravity;
   578       HHGear.dY:= HHGear.dY + cGravity;
   566       tt:= Gear.Elasticity;
   579       tt:= Gear.Elasticity;
   567       tx:= 0;
   580       tx:= 0;
   568       ty:= 0;
   581       ty:= 0;
   569       while tt > 20 do
   582       while tt > 20 do
   570             begin
   583             begin
   571             if  TestCollisionXwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dX))
   584             if  TestCollisionXwithXYShift(Gear, round(tx), round(ty), hwSign(Gear.dX))
   572              or TestCollisionYwithXYShift(Gear, round(tx), round(ty), Sign(Gear.dY)) then
   585              or TestCollisionYwithXYShift(Gear, round(tx), round(ty), hwSign(Gear.dY)) then
   573                 begin
   586                 begin
   574                 Gear.X:= Gear.X + tx;
   587                 Gear.X:= Gear.X + tx;
   575                 Gear.Y:= Gear.Y + ty;
   588                 Gear.Y:= Gear.Y + ty;
   576                 Gear.Elasticity:= tt;
   589                 Gear.Elasticity:= tt;
   577                 Gear.doStep:= doStepRopeWork;
   590                 Gear.doStep:= doStepRopeWork;
   863 var HHGear: PGear;
   876 var HHGear: PGear;
   864 begin
   877 begin
   865 AllInactive:= false;
   878 AllInactive:= false;
   866 HHGear:= PHedgehog(Gear.Hedgehog).Gear;
   879 HHGear:= PHedgehog(Gear.Hedgehog).Gear;
   867 HHGear.X:= round(HHGear.X) - 0.5;
   880 HHGear.X:= round(HHGear.X) - 0.5;
   868 HHGear.dX:= 0.0000001 * Sign(HHGear.dX);
   881 HHGear.dX:= 0.0000001 * hwSign(HHGear.dX);
   869 HHGear.dY:= -0.30;
   882 HHGear.dY:= -0.30;
   870 
   883 
   871 Gear.X:= HHGear.X;
   884 Gear.X:= HHGear.X;
   872 Gear.dX:= Sign(HHGear.dX)* 0.45;
   885 Gear.dX:= hwSign(HHGear.dX)* 0.45;
   873 Gear.dY:= -0.9;
   886 Gear.dY:= -0.9;
   874 Gear.doStep:= doStepFirePunchWork;
   887 Gear.doStep:= doStepFirePunchWork;
   875 DrawTunnel(HHGear.X - cHHRadius, HHGear.Y + 1, 0.5, 0.0, cHHRadius * 4, 5);
   888 DrawTunnel(HHGear.X - cHHRadius, HHGear.Y + 1, 0.5, 0.0, cHHRadius * 4, 5);
   876 end;
   889 end;
   877 
   890