hedgewars/uGearsHandlersRope.pas
changeset 13978 818969052920
parent 13961 2568fa516733
child 14287 6015b74eea55
equal deleted inserted replaced
13977:c471282572c1 13978:818969052920
   212     tx := HHGear^.X;
   212     tx := HHGear^.X;
   213     ty := HHGear^.Y;
   213     ty := HHGear^.Y;
   214 
   214 
   215     if ((Gear^.Message and gmDown) <> 0) and (Gear^.Elasticity < Gear^.Friction) then
   215     if ((Gear^.Message and gmDown) <> 0) and (Gear^.Elasticity < Gear^.Friction) then
   216         if not ((TestCollisionXwithXYShift(HHGear, _2*hwSign(ropeDx), 0, hwSign(ropeDx), true) <> 0)
   216         if not ((TestCollisionXwithXYShift(HHGear, _2*hwSign(ropeDx), 0, hwSign(ropeDx), true) <> 0)
   217         or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, 1*hwSign(ropeDy), hwSign(ropeDy)) <> 0))) then
   217         or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, hwSign(ropeDy), hwSign(ropeDy)) <> 0))) then
   218             Gear^.Elasticity := Gear^.Elasticity + _1_2;
   218             Gear^.Elasticity := Gear^.Elasticity + _1_2;
   219 
   219 
   220     if ((Gear^.Message and gmUp) <> 0) and (Gear^.Elasticity > _30) then
   220     if ((Gear^.Message and gmUp) <> 0) and (Gear^.Elasticity > _30) then
   221         if not ((TestCollisionXwithXYShift(HHGear, -_2*hwSign(ropeDx), 0, -hwSign(ropeDx), true) <> 0)
   221         if not ((TestCollisionXwithXYShift(HHGear, -_2*hwSign(ropeDx), 0, -hwSign(ropeDx), true) <> 0)
   222         or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, 1*-hwSign(ropeDy), -hwSign(ropeDy)) <> 0))) then
   222         or ((ropeDy.QWordValue <> 0) and (TestCollisionYwithXYShift(HHGear, 0, -hwSign(ropeDy), -hwSign(ropeDy)) <> 0))) then
   223             Gear^.Elasticity := Gear^.Elasticity - _1_2;
   223             Gear^.Elasticity := Gear^.Elasticity - _1_2;
   224 
   224 
   225     HHGear^.X := Gear^.X + mdX * Gear^.Elasticity;
   225     HHGear^.X := Gear^.X + mdX * Gear^.Elasticity;
   226     HHGear^.Y := Gear^.Y + mdY * Gear^.Elasticity;
   226     HHGear^.Y := Gear^.Y + mdY * Gear^.Elasticity;
   227 
   227 
   228     HHGear^.dX := HHGear^.X - tx;
   228     HHGear^.dX := HHGear^.X - tx;
   229     HHGear^.dY := HHGear^.Y - ty;
   229     HHGear^.dY := HHGear^.Y - ty;
   230     ////
       
   231 
       
   232 
   230 
   233     haveDivided := false;
   231     haveDivided := false;
   234     // check whether rope needs dividing
   232     // check whether rope needs dividing
   235 
   233 
   236     len := Gear^.Elasticity - _5;
   234     len := Gear^.Elasticity - _5;
   427 procedure doStepRopeAttach(Gear: PGear);
   425 procedure doStepRopeAttach(Gear: PGear);
   428 var
   426 var
   429     HHGear: PGear;
   427     HHGear: PGear;
   430     tx, ty, tt: hwFloat;
   428     tx, ty, tt: hwFloat;
   431 begin
   429 begin
   432     
       
   433     Gear^.X := Gear^.X - Gear^.dX;
   430     Gear^.X := Gear^.X - Gear^.dX;
   434     Gear^.Y := Gear^.Y - Gear^.dY;
   431     Gear^.Y := Gear^.Y - Gear^.dY;
   435     Gear^.Elasticity := Gear^.Elasticity + _1;
   432     Gear^.Elasticity := Gear^.Elasticity + _1;
   436 
   433 
   437     HHGear := Gear^.Hedgehog^.Gear;
   434     HHGear := Gear^.Hedgehog^.Gear;
   464         begin
   461         begin
   465         doStepHedgehogMoving(HHGear);
   462         doStepHedgehogMoving(HHGear);
   466         Gear^.X := Gear^.X + HHGear^.dX;
   463         Gear^.X := Gear^.X + HHGear^.dX;
   467         Gear^.Y := Gear^.Y + HHGear^.dY;
   464         Gear^.Y := Gear^.Y + HHGear^.dY;
   468 
   465 
       
   466         // hedgehog can teleport up to 5 pixels upwards when sliding,
       
   467         // so we have to give up the maintained rope length
       
   468         // after doStepHedgehogMoving() call and recalculate
       
   469         // it based on the gear and current hedgehog positions
       
   470         Gear^.Elasticity:= int2hwFloat(hwRound(Distance(Gear^.X - HHGear^.X, Gear^.Y - HHGear^.Y) + _0_001));
   469 
   471 
   470         tt := Gear^.Elasticity;
   472         tt := Gear^.Elasticity;
   471         tx := _0;
   473         tx := _0;
   472         ty := _0;
   474         ty := _0;
   473         while tt > _20 do
   475         while tt > _20 do
   476                 begin
   478                 begin
   477                 Gear^.X := Gear^.X + tx;
   479                 Gear^.X := Gear^.X + tx;
   478                 Gear^.Y := Gear^.Y + ty;
   480                 Gear^.Y := Gear^.Y + ty;
   479                 Gear^.Elasticity := tt;
   481                 Gear^.Elasticity := tt;
   480                 Gear^.doStep := @doStepRopeWork;
   482                 Gear^.doStep := @doStepRopeWork;
       
   483 
   481                 PlaySound(sndRopeAttach);
   484                 PlaySound(sndRopeAttach);
   482                 with HHGear^ do
   485                 with HHGear^ do
   483                     begin
   486                     begin
   484                     State := State and (not (gstAttacking or gstHHJumping or gstHHHJump));
   487                     State := State and (not (gstAttacking or gstHHJumping or gstHHHJump));
   485                     Message := Message and (not gmAttack)
   488                     Message := Message and (not gmAttack)
   486                     end;
   489                     end;
   487 
   490 
   488                 RopeRemoveFromAmmo(Gear, HHGear);
   491                 RopeRemoveFromAmmo(Gear, HHGear);
   489 
       
   490                 tt := _0;
       
   491                 exit
   492                 exit
   492                 end;
   493                 end;
   493             tx := tx + Gear^.dX + Gear^.dX;
   494             tx := tx + Gear^.dX + Gear^.dX;
   494             ty := ty + Gear^.dY + Gear^.dY;
   495             ty := ty + Gear^.dY + Gear^.dY;
   495             tt := tt - _2;
   496             tt := tt - _2;