624 end; |
624 end; |
625 |
625 |
626 //////////////////////////////////////////////////////////////////////////////// |
626 //////////////////////////////////////////////////////////////////////////////// |
627 |
627 |
628 procedure doStepRopeWork(Gear: PGear); |
628 procedure doStepRopeWork(Gear: PGear); |
629 const flCheck: boolean = false; |
|
630 var HHGear: PGear; |
629 var HHGear: PGear; |
631 len, cs, cc, tx, ty, nx, ny, ropeDx, ropeDy: hwFloat; |
630 len, cs, cc, tx, ty, nx, ny, ropeDx, ropeDy: hwFloat; |
632 lx, ly: LongInt; |
631 lx, ly: LongInt; |
633 haveCollision: boolean; |
632 haveCollision, |
|
633 haveDivided: boolean; |
634 |
634 |
635 procedure DeleteMe; |
635 procedure DeleteMe; |
636 begin |
636 begin |
637 with HHGear^ do |
637 with HHGear^ do |
638 begin |
638 begin |
658 if (Gear^.Message and gm_Left <> 0) then HHGear^.dX:= HHGear^.dX - _0_0002 else |
658 if (Gear^.Message and gm_Left <> 0) then HHGear^.dX:= HHGear^.dX - _0_0002 else |
659 if (Gear^.Message and gm_Right <> 0) then HHGear^.dX:= HHGear^.dX + _0_0002; |
659 if (Gear^.Message and gm_Right <> 0) then HHGear^.dX:= HHGear^.dX + _0_0002; |
660 |
660 |
661 if not TestCollisionYwithGear(HHGear, 1) then HHGear^.dY:= HHGear^.dY + cGravity; |
661 if not TestCollisionYwithGear(HHGear, 1) then HHGear^.dY:= HHGear^.dY + cGravity; |
662 |
662 |
663 cc:= ropeDx + HHGear^.dX; |
663 tx:= ropeDx + HHGear^.dX; |
664 cs:= ropeDy + HHGear^.dY; |
664 ty:= ropeDy + HHGear^.dY; |
665 len:= _1 / Distance(cc, cs); |
665 len:= _1 / Distance(tx, ty); |
666 cc:= cc * len; // rope vector plus hedgehog direction vector normalized |
666 tx:= tx * len; // rope vector plus hedgehog direction vector normalized |
667 cs:= cs * len; |
667 ty:= ty * len; |
668 |
668 |
669 nx:= SignAs(cs, HHGear^.dX) * 7; // hedgehog direction normalized with length 7 |
669 haveDivided:= false; |
670 ny:= SignAs(cc, HHGear^.dY) * 7; |
670 // check whether rope needs dividing |
671 |
671 len:= _1 / Distance(ropeDx, ropeDy); // old rope pos |
672 flCheck:= not flCheck; |
672 nx:= ropeDx * len; |
673 if flCheck then // check whether rope needs dividing |
673 ny:= ropeDy * len; |
674 begin |
674 |
675 len:= Gear^.Elasticity - _20; |
675 len:= Gear^.Elasticity - _20; |
676 while len > _5 do |
676 while len > _5 do |
677 begin |
677 begin |
678 tx:= cc*len; |
678 lx:= hwRound(Gear^.X + tx * len); |
679 ty:= cs*len; |
679 ly:= hwRound(Gear^.Y + ty * len); |
680 lx:= hwRound(Gear^.X + tx + nx); |
|
681 ly:= hwRound(Gear^.Y + ty + ny); |
|
682 if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0) and (Land[ly, lx] <> 0) then |
680 if ((ly and $FFFFFC00) = 0) and ((lx and $FFFFF800) = 0) and (Land[ly, lx] <> 0) then |
683 begin |
681 begin |
684 with RopePoints.ar[RopePoints.Count] do |
682 with RopePoints.ar[RopePoints.Count] do |
685 begin |
683 begin |
686 X:= Gear^.X; |
684 X:= Gear^.X; |
687 Y:= Gear^.Y; |
685 Y:= Gear^.Y; |
688 if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle(ropeDx, ropeDy); |
686 if RopePoints.Count = 0 then RopePoints.HookAngle:= DxDy2Angle(Gear^.dY, Gear^.dX); |
689 b:= (cc * HHGear^.dY) > (cs * HHGear^.dX); |
687 b:= (tx * HHGear^.dY) > (ty * HHGear^.dX); |
690 dLen:= len |
688 dLen:= len |
691 end; |
689 end; |
692 Gear^.X:= Gear^.X + tx; |
690 Gear^.X:= Gear^.X + nx * len; |
693 Gear^.Y:= Gear^.Y + ty; |
691 Gear^.Y:= Gear^.Y + ny * len; |
694 inc(RopePoints.Count); |
692 inc(RopePoints.Count); |
695 TryDo(RopePoints.Count <= MAXROPEPOINTS, 'Rope points overflow', true); |
693 TryDo(RopePoints.Count <= MAXROPEPOINTS, 'Rope points overflow', true); |
696 Gear^.Elasticity:= Gear^.Elasticity - len; |
694 Gear^.Elasticity:= Gear^.Elasticity - len; |
697 Gear^.Friction:= Gear^.Friction - len; |
695 Gear^.Friction:= Gear^.Friction - len; |
|
696 haveDivided:= true; |
698 break |
697 break |
699 end; |
698 end; |
700 len:= len - _3 |
699 len:= len - _0_3 // should be the same as increase step |
701 end; |
700 end; |
702 end else |
701 |
|
702 if not haveDivided then |
703 if RopePoints.Count > 0 then // check whether the last dividing point could be removed |
703 if RopePoints.Count > 0 then // check whether the last dividing point could be removed |
704 begin |
704 begin |
705 tx:= RopePoints.ar[Pred(RopePoints.Count)].X; |
705 tx:= RopePoints.ar[Pred(RopePoints.Count)].X; |
706 ty:= RopePoints.ar[Pred(RopePoints.Count)].Y; |
706 ty:= RopePoints.ar[Pred(RopePoints.Count)].Y; |
707 if RopePoints.ar[Pred(RopePoints.Count)].b xor ((tx - Gear^.X) * (ty - HHGear^.Y) > (tx - HHGear^.X) * (ty - Gear^.Y)) then |
707 if RopePoints.ar[Pred(RopePoints.Count)].b xor ((tx - Gear^.X) * (ty - HHGear^.Y) > (tx - HHGear^.X) * (ty - Gear^.Y)) then |